试图解码这个json:
$json = '{"d":{"results":[{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=\u0027web+spell+relatedsearch\u0027&Query=\u0027\"\u003e\u003c/a\u003e\u003cimg src=\"&$skip=0&$top=1#\"\u003e\u003cscript\u003ealert(\u00273\u0027);\u003c/script\u003e\"\u0027&Market=\u0027it-IT\u0027&Adult=\u0027Strict\u0027&Options=\u0027DisableLocationDetection+EnableHighlighting\u0027&WebSearchOptions=\u0027DisableQueryAlterations\u0027","type":"ExpandableSearchResult"},"ID":"5afc1ab9-f4a7-43e1-9d14-dbec42f83c0c","WebTotal":"4","WebOffset":"0","ImageTotal":"","ImageOffset":"","VideoTotal":"","VideoOffset":"","NewsTotal":"","NewsOffset":"","SpellingSuggestionsTotal":"","AlteredQuery":"","AlterationOverrideQuery":"","Web":[{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?$skip=0&$top=1","type":"WebResult"},"ID":"38cc61c8-4ce2-4013-92ee-a2fa4de3abcc","Title":"apache 2.2.21 exploits - Page 2 - Code Exploits Collection","Description":"... script\u003e password_verify \"\u003e\u003cscript\u003ealert(2);\u003c/script\u003e firstname \"\u003e\u003cscript\u003ealert(3);\u003c/script ... 703F67657470776E65643D: Administrators\u003c/a\u003e\u003cimg src=\"http://192.168.0.15/learn ...","DisplayUrl":"exploitsdownload.com/search/apache%202.2.21/2","Url":"http://exploitsdownload.com/search/apache%202.2.21/2"},{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?$skip=1&$top=1","type":"WebResult"},"ID":"df1b6d37-efc1-4d3c-bed5-7d6e34a3d686","Title":"siteniz için htlm kodları - Sayfa 3 - Baktabul Forum","Description":"... gelecek ve sooon\") \u003c/script\u003e \u003cscript\u003e alert(\"4!!\") \u003c/script\u003e \u003cscript\u003e alert(\"3!!!\") \u003c/script\u003e \u003cscript\u003e ... BURAYA YAZIN!!!\u0027,500,300); return false\" \u003e \u003e\u003e\u003eGİRİŞ \u003c\u003c\u003c\u003c\u003c/a\u003e \u003cIMG SRC= \"http ...","DisplayUrl":"www.baktabul.net/webmaster/42351-siteniz-icin-htlm-kodlari-3.html","Url":"http://www.baktabul.net/webmaster/42351-siteniz-icin-htlm-kodlari-3.html"},{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?$skip=2&$top=1","type":"WebResult"},"ID":"fab98f52-bbe6-40f7-805d-5ab14b503827","Title":"php 5.2.17 exploits - Page 1 - Code Exploits Collection","Description":"... trace_results.php?product_id=117&project_id=40&funder=31\"\u003e\u003cscript\u003ealert(3);\u003c/script ... 703F67657470776E65643D: Administrators\u003c/a\u003e\u003cimg src=\"http://192.168.0.15/learn ...","DisplayUrl":"exploitsdownload.com/search/php%205.2.17","Url":"http://exploitsdownload.com/search/php%205.2.17/"},{"__metadata":{"uri":"https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?$skip=3&$top=1","type":"WebResult"},"ID":"82b3c849-4cdc-409a-95a8-a74310b723aa","Title":"DEV ARŞİV \u0027\u0027Hazır kodlar\u0027ın %90 burada\u0027\u0027 İçeri buyrun\u003e\u003e\u003e","Description":"... ve sooon\")\u003c/script\u003e \u003cscript\u003ealert(\"4!!\")\u003c/script\u003e \u003cscript\u003ealert(\"3!!!\")\u003c/script ... BURAYA YAZIN!!!\u0027,500,300); return false\"\u003e\u003e\u003e\u003eGİRİŞ\u003c\u003c\u003c\u003c\u003c/a\u003e\u003cIMG SRC=\"http ...","DisplayUrl":"www.zevkli.org/dev-ar350304v-haz305r-kodlar305n-90-burada-304231...","Url":"http://www.zevkli.org/dev-ar350304v-haz305r-kodlar305n-90-burada-304231eri-buyrungtgtgt-t180384.html"}],"Image":[],"Video":[],"News":[],"RelatedSearch":[],"SpellingSuggestions":[]}]}}';
php返回给我使用var_dump(json_decode($jsonOriginalResults, true));
解码了 \u003c 字符的错误数组,但为什么呢?
我只是期待这样的结果:
array(1) {
["d"]=>
array(1) {
["results"]=>
array(1) {
[0]=>
array(19) {
["__metadata"]=>
array(2) {
["uri"]=>
string(403) "https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=\u0027web+spell+relatedsearch\u0027&Query=\u0027"\u003e\u003c/a\u003e\u003cimg src="&=0&=1#"\u003e\u003cscript\u003ealert(\u00273\u0027);\u003c/script\u003e"\u0027&Market=\u0027it-IT\u0027&Adult=\u0027Strict\u0027&Options=\u0027DisableLocationDetection+EnableHighlighting\u0027&WebSearchOptions=\u0027DisableQueryAlterations\u0027"
["type"]=>
string(22) "ExpandableSearchResult"
}
["ID"]=>
string(36) "5afc1ab9-f4a7-43e1-9d14-dbec42f83c0c"
["WebTotal"]=>
string(1) "4"
["WebOffset"]=>
string(1) "0"
["ImageTotal"]=>
string(0) ""
["ImageOffset"]=>
string(0) ""
["VideoTotal"]=>
string(0) ""
["VideoOffset"]=>
string(0) ""
["NewsTotal"]=>
string(0) ""
["NewsOffset"]=>
string(0) ""
["SpellingSuggestionsTotal"]=>
string(0) ""
["AlteredQuery"]=>
string(0) ""
["AlterationOverrideQuery"]=>
string(0) ""
["Web"]=>
array(4) {
[0]=>
array(6) {
["__metadata"]=>
array(2) {
["uri"]=>
string(144) "https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?=0&=1"
["type"]=>
string(9) "WebResult"
}
["ID"]=>
string(36) "38cc61c8-4ce2-4013-92ee-a2fa4de3abcc"
["Title"]=>
string(58) "apache 2.2.21 exploits - Page 2 - Code Exploits Collection"
["Description"]=>
string(257) "... script\u003e password_verify "\u003e\u003cscript\u003ealert(2);\u003c/script\u003e firstname "\u003e\u003cscript\u003ealert(3);\u003c/scriptî€ ... 703F67657470776E65643D: Administrators\u003c/a\u003e\u003cimg srcî€="http://192.168.0.15/learn ..."
["DisplayUrl"]=>
string(45) "exploitsdownload.com/search/apache%202.2.21/2"
["Url"]=>
string(52) "http://exploitsdownload.com/search/apache%202.2.21/2"
}
[1]=>
array(6) {
["__metadata"]=>
array(2) {
["uri"]=>
string(144) "https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?=1&=1"
["type"]=>
string(9) "WebResult"
}
["ID"]=>
string(36) "df1b6d37-efc1-4d3c-bed5-7d6e34a3d686"
["Title"]=>
string(54) "siteniz için htlm kodları - Sayfa 3 - Baktabul Forum"
["Description"]=>
string(326) "... gelecek ve sooon") \u003c/script\u003e \u003cscript\u003e alert("4!!") \u003c/script\u003e \u003cscript\u003e alert("3!!!") \u003c/scriptî€\u003e \u003cscript\u003e ... BURAYA YAZIN!!!\u0027,500,300); return false" \u003e \u003e\u003e\u003eGÄ°RÄ°Åž \u003c\u003c\u003c\u003c\u003c/a\u003e \u003cIMG SRCî€= "http ..."
["DisplayUrl"]=>
string(65) "www.baktabul.net/webmaster/42351-siteniz-icin-htlm-kodlari-3.html"
["Url"]=>
string(72) "http://www.baktabul.net/webmaster/42351-siteniz-icin-htlm-kodlari-3.html"
}
[2]=>
array(6) {
["__metadata"]=>
array(2) {
["uri"]=>
string(144) "https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?=2&=1"
["type"]=>
string(9) "WebResult"
}
["ID"]=>
string(36) "fab98f52-bbe6-40f7-805d-5ab14b503827"
["Title"]=>
string(55) "php 5.2.17 exploits - Page 1 - Code Exploits Collection"
["Description"]=>
string(228) "... trace_results.php?product_id=117&project_id=40&funder=31"\u003e\u003cscript\u003ealert(3);\u003c/scriptî€ ... 703F67657470776E65643D: Administrators\u003c/a\u003e\u003cimg srcî€="http://192.168.0.15/learn ..."
["DisplayUrl"]=>
string(40) "exploitsdownload.com/search/php%205.2.17"
["Url"]=>
string(48) "http://exploitsdownload.com/search/php%205.2.17/"
}
[3]=>
array(6) {
["__metadata"]=>
array(2) {
["uri"]=>
string(144) "https://api.datamarket.azure.com/Data.ashx/Bing/Search/ExpandableSearchResultSet(guid\u00275afc1ab9-f4a7-43e1-9d14-dbec42f83c0c\u0027)/Web?=3&=1"
["type"]=>
string(9) "WebResult"
}
["ID"]=>
string(36) "82b3c849-4cdc-409a-95a8-a74310b723aa"
["Title"]=>
string(102) "DEV ARŞİV \u0027\u0027Hazır kodlar\u0027ın %90 burada\u0027\u0027 İçeri buyrun\u003e\u003e\u003e"
["Description"]=>
string(283) "... ve sooon")\u003c/script\u003e \u003cscript\u003ealert("4!!")\u003c/script\u003e \u003cscript\u003ealert("3!!!")\u003c/scriptî€ ... BURAYA YAZIN!!!\u0027,500,300); return false"\u003e\u003e\u003e\u003eGÄ°RÄ°Åž\u003c\u003c\u003c\u003c\u003c/a\u003e\u003cIMG SRCî€="http ..."
["DisplayUrl"]=>
string(67) "www.zevkli.org/dev-ar350304v-haz305r-kodlar305n-90-burada-304231..."
["Url"]=>
string(100) "http://www.zevkli.org/dev-ar350304v-haz305r-kodlar305n-90-burada-304231eri-buyrungtgtgt-t180384.html"
}
}
["Image"]=>
array(0) {
}
["Video"]=>
array(0) {
}
["News"]=>
array(0) {
}
["RelatedSearch"]=>
array(0) {
}
["SpellingSuggestions"]=>
array(0) {
}
}
}
}
}
使用此自定义函数获得此结果:
function json_decoder($json) {
$comment = false;
$out = '$x=';
for ($i = 0; $i < strlen($json); $i++) {
if (!$comment) {
if (($json[$i] == '{') || ($json[$i] == '['))
$out .= ' array(';
else if (($json[$i] == '}') || ($json[$i] == ']'))
$out .= ')';
else if ($json[$i] == ':')
$out .= '=>';
else
$out .= $json[$i];
} else
$out .= $json[$i];
if ($json[$i] == '"' && $json[($i - 1)] != "\\")
$comment = !$comment;
}
eval($out . ';');
return $x;
}
但我想使用 php json_decode 函数而不是自定义函数......有什么建议吗?