我需要使用PHP curl发布JSON数据。搜索了这个网站之后,我找到了一些例子并了解到数据应该作为数组提交,但我仍然得到“({”message“:”cjson decoding error“,”code“:500,”error“:true})”发布数据后每次都出错。
原始数据看起来像这样(来自firefox live httpd headers):
{"nodes":[{"id":"","type":"some_type","parentId":"ROOT","refId":null,"href":"","text":"New","desc":"","tags":"","cr":123}],"revision":11,"token":"some_token"}
现在,这是我尝试通过curl提交的数据
json_encode(array("nodes"=>array("id"=>"", "type"=>"some_type", "parentId"=>"ROOT", "refId"=>"", "href"=>"", "text"=>"New", "desc"=>"", "tags"=>"", "cr"=>"123"), "revision"=>"11", "token"=>"some_token"));
有人能告诉我这里有什么问题吗?
答案 0 :(得分:0)
如果您回显第二行,您会发现它与您在第一行中发布的内容不匹配。
正确的版本如下:
json_encode(array("nodes"=>array(array("id"=>"", "type"=>"some_type", "parentId"=>"ROOT", "refId"=>"", "href"=>"", "text"=>"New", "desc"=>"", "tags"=>"", "cr"=>"123")), "revision"=>"11", "token"=>"some_token"));
现在它与您在第一行中发布的结构相同。 (请参阅节点列表周围的附加数组。您需要额外的数组(),因为格式似乎支持发布多个“节点”的想法。