ホームページ >バックエンド開発 >PHPチュートリアル >単純な JSON の読み取りが間違っている可能性があります。
<?
$pingluninfo = 993d5c9b5d4d7d7eecce9b5581091ad2
总は出错误のデータ格式
json に問題があります。
json_encode 後の中国語はこうなりません
<?php $pingluninfo = <<<EOT{ "title":"123", "url":"http://localhost/?p=9", "ttime":1401327899094, "sourceid":"9", "parentid":"0", "categoryid":"", "ownerid":"", "metadata":"", "comments":[ { "cmtid":"358", "ctime":1401327899094, "content":"2013年8月1日18:36:29 O(∩_∩)O~", "replyid":"0", "user":{ "userid":"1", "nickname":"admin", "usericon":"", "userurl":"", "usermetadata":{ "area": "北京市", "gender": "1", "kk": "", "level": 1 } }, "ip":"127.0.0.1", "useragent":"Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0", "channeltype":"1", "from":"", "spcount":"", "opcount":"", "attachment":[ { "type":1, "desc":"", "url":"http://img.sohu.itc/xxxx" } ] } ]}EOT;$pingluninfo = json_decode($pingluninfo, true);if(!$pingluninfo) { die('错误的数据格式');}echo "<pre class="brush:php;toolbar:false">";print_r($pingluninfo);echo "";
Array( [title] => 123 [url] => http://localhost/?p=9 [ttime] => 1401327899094 [sourceid] => 9 [parentid] => 0 [categoryid] => [ownerid] => [metadata] => [comments] => Array ( [0] => Array ( [cmtid] => 358 [ctime] => 1401327899094 [content] => 2013年8月1日18:36:29 O(∩_∩)O~ [replyid] => 0 [user] => Array ( [userid] => 1 [nickname] => admin [usericon] => [userurl] => [usermetadata] => Array ( [area] => 北京市 [gender] => 1 [kk] => [level] => 1 ) ) [ip] => 127.0.0.1 [useragent] => Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0 [channeltype] => 1 [from] => [spcount] => [opcount] => [attachment] => Array ( [0] => Array ( [type] => 1 [desc] => [url] => http://img.sohu.itc/xxxx ) ) ) ))
引用符を完成させてください!
"ttime":1401327899094、"ttime":"1401327899094" である必要があります。
その他の同様のもの
echo '<meta http-equiv="content-type" content="text/html;charset=utf-8">';$pingluninfo = <<<EOT{ "title":"123", "url":"http://localhost/?p=9", "ttime":1401327899094, "sourceid":"9", "parentid":"0", "categoryid":"", "ownerid":"", "metadata":"", "comments":[ { "cmtid":"358", "ctime":1401327899094, "content":"2013年8月1日18:36:29 O(∩_∩)O~", "replyid":"0", "user":{ "userid":"1", "nickname":"admin", "usericon":"", "userurl":"", "usermetadata":{ "area": "北京市", "gender": "1", "kk": "", "level": 1 } }, "ip":"127.0.0.1", "useragent":"Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0", "channeltype":"1", "from":"", "spcount":"", "opcount":"", "attachment":[ { "type":1, "desc":"", "url":"http://img.sohu.itc/xxxx" } ] } ]}EOT;$pingluninfo = json_decode($pingluninfo, true);if(!$pingluninfo) { die('错误的数据格式');}else{ print_r($pingluninfo);}
それは新しいバージョンですよね?数値は最大値を超えていると推定されます
あなたのは新しいバージョンですよね?数値型は最大値を超えていると推定されます
テストが正常であることを示す上記のコードをコピーしましたが、データエラーが発生しただけです。
環境問題のようです
rreee
テストしましたが正常です。
( [title] => 123 [url] => http://localhost/?p=9 [ttime] => 1401327899094 [sourceid] => 9 [parentid] => 0 [categoryid] => [ownerid] => [metadata] => [comments] => Array ( [0] => Array ( [cmtid] => 358 [ctime] => 1401327899094 [content] => 2013年8月1日18:36:29 O(∩_∩)O~ [replyid] => 0 [user] => Array ( [userid] => 1 [nickname] => admin [usericon] => [userurl] => [usermetadata] => Array ( [area] => 北京市 [gender] => 1 [kk] => [level] => 1 ) ) [ip] => 127.0.0.1 [useragent] => Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0 [channeltype] => 1 [from] => [spcount] => [opcount] => [attachment] => Array ( [0] => Array ( [type] => 1 [desc] => [url] => http://img.sohu.itc/xxxx ) ) ) ))
テストが正常であることを示す上記のコードをコピーしましたが、データ エラーが発生しただけです。
環境問題のようです
echo '<meta http-equiv="content-type" content="text/html;charset=utf-8">';$pingluninfo = <<<EOT{ "title":"123", "url":"http://localhost/?p=9", "ttime":1401327899094, "sourceid":"9", "parentid":"0", "categoryid":"", "ownerid":"", "metadata":"", "comments":[ { "cmtid":"358", "ctime":1401327899094, "content":"2013年8月1日18:36:29 O(∩_∩)O~", "replyid":"0", "user":{ "userid":"1", "nickname":"admin", "usericon":"", "userurl":"", "usermetadata":{ "area": "北京市", "gender": "1", "kk": "", "level": 1 } }, "ip":"127.0.0.1", "useragent":"Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0", "channeltype":"1", "from":"", "spcount":"", "opcount":"", "attachment":[ { "type":1, "desc":"", "url":"http://img.sohu.itc/xxxx" } ] } ]}EOT;$pingluninfo = json_decode($pingluninfo, true);if(!$pingluninfo) { die('错误的数据格式');}else{ print_r($pingluninfo);}
( [title] => 123 [url] => http://localhost/?p=9 [ttime] => 1401327899094 [sourceid] => 9 [parentid] => 0 [categoryid] => [ownerid] => [metadata] => [comments] => Array ( [0] => Array ( [cmtid] => 358 [ctime] => 1401327899094 [content] => 2013年8月1日18:36:29 O(∩_∩)O~ [replyid] => 0 [user] => Array ( [userid] => 1 [nickname] => admin [usericon] => [userurl] => [usermetadata] => Array ( [area] => 北京市 [gender] => 1 [kk] => [level] => 1 ) ) [ip] => 127.0.0.1 [useragent] => Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0 [channeltype] => 1 [from] => [spcount] => [opcount] => [attachment] => Array ( [0] => Array ( [type] => 1 [desc] => [url] => http://img.sohu.itc/xxxx ) ) ) ))