我无法将其变成数组..
我应该用php解读这个:
({serverTimestamp: "Wed, 28 Mar 2012 11:40:26 +0000",users: [{userId: "username",statuscode:0,floatingPL:-1000.00,balance:50000,equity:40000,freeMargin:4000,marginInUse:30.11,currency:"EUR",closedPL:5692.85,creditFacility:0,mostRecentUpload:"Wed, 28 Mar 2012 11:39:58 +0000"}]})
它看起来像是序列化的,但是unserialize()在var_dump()中给出了false。 Json_decode给出了相同的..
谢谢
答案 0 :(得分:2)
示例:http://codepad.org/tK4zIJj1
(...)
括号json_decode()
http://hu2.php.net/manual/en/function.json-decode.php serialize()
vs unserialize()
是PHP自己的数据来自/到字符串转换函数,它可以处理循环引用,类等,但通常与外部世界不兼容。
如果没有帮助,你可以使用这个快速组合功能:
function fix_json( $j ){
$j = trim( $j );
$j = ltrim( $j, '(' );
$j = rtrim( $j, ')' );
$a = preg_split('#(?<!\\\\)\"#', $j );
for( $i=0; $i < count( $a ); $i+=2 ){
$s = $a[$i];
$s = preg_replace('#([^\s\[\]\{\}\:\,]+):#', '"\1":', $s );
$a[$i] = $s;
}
//var_dump($a);
$j = implode( '"', $a );
//var_dump( $j );
return $j;
}
答案 1 :(得分:0)
是的,ghoti是对的。为了将PHP转换为JSON,必须以双引号引用所有属性名称。在这种情况下,这是正确的JSON:
({"serverTimestamp": "Wed, 28 Mar 2012 11:40:26 +0000","users": [{"userId": "username","statuscode":0,"floatingPL":-1000.00,"balance":50000,"equity":40000,"freeMargin":4000,"marginInUse":30.11,"currency":"EUR","closedPL":5692.85,"creditFacility":0,"mostRecentUpload":"Wed, 28 Mar 2012 11:39:58 +0000"}]})