$nodeary=array(); while($row=mssql_fetch_array($rs)){ $description=strstr(//,,$row['description']); array_push($nodeary,'{fchritemid:'.$row[fchritemid].',fchritemtypeid:'.$row[fchritemtypeid].',fchritemname:'.$row[fchritemname].',flotquoteprice:'.$row[flotquoteprice].',description:'.trim($description).',fdtmlastmodifytime:'.$row[fdtmlastmodifytime].',sales_volume:'.$row[sales_volume].'}'); } $tbstr=implode(',',$nodeary); ?>{table:[]}
这里的description 字段有中文,只要把这个字段去掉就可以了,
header(content-type:text/html; charset=utf-8); $ch = curl_init(); curl_setopt($ch, curlopt_url, $remoteapibasepath . sync2shop_api/item.php); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_header, 0); $output = curl_exec($ch); curl_close($ch); $obj=json_decode(iconv(gb2312,utf-8,$output)); var_dump( $obj); //$obj=json_decode($output); $rscount=count($obj->table); $han=fopen(debug.php,a); fwrite($han,$output.---------.$rscount); fclose($han);
我是这么解析的,不知道哪里有错误,有谁帮忙看看!
回复讨论(解决方案) php 的 json 函数只对 utf-8 编码的的字符串有效
你需要先将字符串转成 utf-8 编码的,然后再解码
只能说你拿到的 json 不合规范,中文应该都是 \uxxxx 形式
已经设置编码utf-8 编码了,但是还是不行啊
只能说你拿到的 json 不合规范,中文应该都是 \uxxxx 形式
数据取出的数据怎么会有反斜杠呢?自己加一个么?
我的数据是从远程数据库取的,难道会有影响吗?
你最好贴出你的数据,只要格式正确。不会有问题的
$s = '{a:我的,b:数据,c:[是从远程数据库,取的],d:难道会有影响吗?}';$s = iconv('gbk', 'utf-8', $s);print_r(json_decode($s));
stdclass object( [a] => 我的 [b] => 数据 [c] => array ( [0] => 是从远程数据库 [1] => 取的 ) [d] => 难道会有影响吗?)
你最好贴出你的数据,只要格式正确。不会有问题的
$s = '{a:我的,b:数据,c:[是从远程数据库,取的],d:难道会有影响吗?}';$s = iconv('gbk', 'utf-8', $s);print_r(json_decode($s));
stdclass object( [a] => 我的 [b] => 数据 [c] => array ( [0] => 是从远程数据库 [1] => 取的 ) [d] => 难道会有影响吗?)
我只截取一部分,数据太多了,麻烦帮忙看看呐!
table:[{fchritemid:1e7d5286-7379-4b6e-b63c-0081596b808f,fchritemtypeid:17e0a935-e0ff-4488-b2f0-cc9f2926c001,fchritemname:h13222s13,flotquoteprice:499.000000,description:高密度的丝光棉面料,手工钉珠的人像艺术款。,fdtmlastmodifytime:,sales_volume:},{fchritemid:e82e5a29-a1bd-4f53-ad65-0147906e224d,fchritemtypeid:73a4e44d-7bf7-49cf-9a75-dcc805d93fdb,fchritemname:h13143c04,flotquoteprice:799.000000,description:,fdtmlastmodifytime:,sales_volume:},{fchritemid:a7fd2243-d39c-49d5-9785-01dd923fa60e,fchritemtypeid:17e0a935-e0ff-4488-b2f0-cc9f2926c001,fchritemname:h13222c04,flotquoteprice:499.000000,description:丝光棉显示高档感,图形用胶印和钉珠的复杂工艺而非普通大众品牌较多使用的平面印花印制,彰显独特的设计点。,fdtmlastmodifytime:,sales_volume:},{fchritemid:4e82d694-ca4c-4134-92ba-027ee10b9100,fchritemtypeid:17e0a935-e0ff-4488-b2f0-cc9f2926c001,fchritemname:h13222c35,flotquoteprice:499.000000,description:高级丝光棉,蜻蜓为元素的创意有趣的图案和品牌logo和金属贴片的再组合方式呈现艺术感的品牌特性。,fdtmlastmodifytime:,sales_volume:},{fchritemid:6d129f91-1869-47be-9aed-02a0e156b120,fchritemtypeid:6dc7f007-c0eb-45fe-94f1-4c792b8feb23,fchritemname:h13456c14,flotquoteprice:3899.000000,description:,fdtmlastmodifytime:,sales_volume:0},{fchritemid:6fa0b24c-6c17-43bb-acae-04369f73fe8d,fchritemtypeid:17e0a935-e0ff-4488-b2f0-cc9f2926c001,fchritemname:h13222c21,flotquoteprice:499.000000,description:,fdtmlastmodifytime:,sales_volume:},{fchritemid:a875f37e-503e-4f25-bcec-04ba7a53d18f,fchritemtypeid:6fd4df7e-3f1e-4b04-90ef-189664add3ea,fchritemname:h13111c13,flotquoteprice:599.000000,description:,fdtmlastmodifytime:,sales_volume:},{fchritemid:4c3e6dfb-f4ce-404d-930d-04be6591965f,fchritemtypeid:6fd4df7e-3f1e-4b04-90ef-189664add3ea,fchritemname:h13111c12,flotquoteprice:699.000000,description:高支高密的全棉面料,前胸对称的色块拼接设计款。,fdtmlastmodifytime:,sales_volume:},
人呢。。。。
$s =< stdclass object
(
[fchritemid] => 1e7d5286-7379-4b6e-b63c-0081596b808f
[fchritemtypeid] => 17e0a935-e0ff-4488-b2f0-cc9f2926c001
[fchritemname] => h13222s13
[flotquoteprice] => 499.000000
[description] => 高密度的丝光棉面料,手工钉珠的人像艺术款。
[fdtmlastmodifytime] =>
[sales_volume] =>
)
[1] => stdclass object
(
[fchritemid] => e82e5a29-a1bd-4f53-ad65-0147906e224d
[fchritemtypeid] => 73a4e44d-7bf7-49cf-9a75-dcc805d93fdb
[fchritemname] => h13143c04
[flotquoteprice] => 799.000000
[description] =>
[fdtmlastmodifytime] =>
[sales_volume] =>
)
[2] => stdclass object
(
[fchritemid] => a7fd2243-d39c-49d5-9785-01dd923fa60e
[fchritemtypeid] => 17e0a935-e0ff-4488-b2f0-cc9f2926c001
[fchritemname] => h13222c04
[flotquoteprice] => 499.000000
[description] => 丝光棉显示高档感,图形用胶印和钉珠的复杂工艺而非普通大众品牌较多使用的平面印花印制,彰显独特的设计点。
[fdtmlastmodifytime] =>
[sales_volume] =>
)
[3] => stdclass object
(
[fchritemid] => 4e82d694-ca4c-4134-92ba-027ee10b9100
[fchritemtypeid] => 17e0a935-e0ff-4488-b2f0-cc9f2926c001
[fchritemname] => h13222c35
[flotquoteprice] => 499.000000
[description] => 高级丝光棉,蜻蜓为元素的创意有趣的图案和品牌logo和金属贴片的再组合方式呈现艺术感的品牌特性。
[fdtmlastmodifytime] =>
[sales_volume] =>
)
[4] => stdclass object
(
[fchritemid] => 6d129f91-1869-47be-9aed-02a0e156b120
[fchritemtypeid] => 6dc7f007-c0eb-45fe-94f1-4c792b8feb23
[fchritemname] => h13456c14
[flotquoteprice] => 3899.000000
[description] =>
[fdtmlastmodifytime] =>
[sales_volume] => 0
)
[5] => stdclass object
(
[fchritemid] => 6fa0b24c-6c17-43bb-acae-04369f73fe8d
[fchritemtypeid] => 17e0a935-e0ff-4488-b2f0-cc9f2926c001
[fchritemname] => h13222c21
[flotquoteprice] => 499.000000
[description] =>
[fdtmlastmodifytime] =>
[sales_volume] =>
)
[6] => stdclass object
(
[fchritemid] => a875f37e-503e-4f25-bcec-04ba7a53d18f
[fchritemtypeid] => 6fd4df7e-3f1e-4b04-90ef-189664add3ea
[fchritemname] => h13111c13
[flotquoteprice] => 599.000000
[description] =>
[fdtmlastmodifytime] =>
[sales_volume] =>
)
[7] => stdclass object
(
[fchritemid] => 4c3e6dfb-f4ce-404d-930d-04be6591965f
[fchritemtypeid] => 6fd4df7e-3f1e-4b04-90ef-189664add3ea
[fchritemname] => h13111c12
[flotquoteprice] => 699.000000
[description] => 高支高密的全棉面料,前胸对称的色块拼接设计款。
[fdtmlastmodifytime] =>
[sales_volume] =>
)
)
)
能帮我远程弄一下么? 我用了curl_init(),curl_exec() ,输出流,获取的 $ch = curl_init(); curl_setopt($ch, curlopt_url, $remoteapibasepath . sync2shop_api/item.php); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_header, 0); $output = curl_exec($ch); curl_close($ch); $obj=json_decode(iconv(gb2312,utf-8,$output));
能帮我远程弄一下么? 我用了curl_init(),curl_exec() ,输出流,获取的 $ch = curl_init(); curl_setopt($ch, curlopt_url, $remoteapibasepath . sync2shop_api/item.php); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_header, 0); $output = curl_exec($ch); curl_close($ch); $obj=json_decode(iconv(gb2312,utf-8,$output));
这里的$output 打印出来就是json的东西,不是直接写在里面的
如果向你这么写,为啥我的会报错呢?
header(content-type:text/html; charset=utf-8); $ch = curl_init(); curl_setopt($ch, curlopt_url, $remoteapibasepath . sync2shop_api/item.php); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_header, 0); $output = curl_exec($ch); curl_close($ch); $obj=<