PHP,JSON解码中的字符无效

我遇到麻烦让json_decode处理我收到的特定字符串.

我把它缩小到这条线:

“systemNotes[6]”: “January 09,2013 12:52 PM – Test Name – Changed Billing Address 2 From to Shipping First Name: Shipping Last Name: Email Address: Shipping Address: Shipping Address 2: Shipping City: Shipping Zip/Postal: Shipping Country: Shipping State: Phone: Billing First Name: Billing Last Name: Billing Address: Billing Address 2: Billing C”

从这个问题中复制json,问题是不可重现的 – 但原始json的代表片段在这里http://codepad.org/ZzrC7rqQ – 并将其放在jsonlint.com中给出:

Parse error on line 3:
...  "systemNotes[6]": "January 09,2013 12
-----------------------^
Expecting 'STRING','NUMBER','NULL','TRUE','FALSE','{','['

这个字符串有什么问题,这样它的json无效?

编辑

我设法找到了确切的代码.

“systemNotes[6]”:”January+09%2C+2013+12%3A52+PM+-+First+Name+-+Changed++Billing+Address+2+From++to+Shipping+First+Name%3A%09+Shipping+Last+Name%3A%09+Email+Address%3A%09+Shipping+Address%3A+%09+Shipping+Address+2%3A+%09+Shipping+City%3A+%09+Shipping+Zip%2FPostal%3A+%09+Shipping+Country%3A+%09+Shipping+State%3A+%09+Phone%3A+%09+Billing+First+Name%3A+%09+Billing+Last+Name%3A+%09+Billing+Address%3A+%09+Billing+Address+2%3A+%09+Billing+C”

这似乎没问题所以也许问题来自于我做parse_str时,这是我正在使用的代码

$response = apiConnection($data);
parse_str($response,$parse);
$each = json_decode($parse['data']);
foreach($each as $key => $order){
   //do something
}
问题是制表符在字符串中无效.

删除像这里http://codepad.org/8fnQphkS这样的标签字符并在jsonlint.com上使用它你会看到它现在看到有效的json.

请查看http://www.ietf.org/rfc/rfc4627.txt?number=4627特别是第2.5节中JSON的规范,其中制表符按名称调出,作为字符串中必须转义的字符之一.

编辑:

这是一种剥离所有选项卡和多个空格并用单个空格字符替换它们的方法

$data = preg_replace('/[ ]{2,}|[\t]/',' ',trim($data));

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...