Help !! Phpjson string question this post was last edited by zl2727 at 16:14:43
$ Proquery = "select * from ##__ keyproduct where typeid = '". $ id. "'Order by corank asc ";
$ Dsql-> SetQuery ($ proquery );
$ Dsql-> Execute ();
$ I = 0;
While ($ row = $ dsql-> GetArray ()){
$ Arrystr. = '{"id ":"'. $ row ["id"]. '"," title ":"'. $ row ["goodstitle"]. '"," goodsTitle ":"'. $ row ["goodstitle"]. '"," price ":"'. $ row
["Price"]. '"," imgUrl ":"'. $ row ["imgurl"]. '"," goodsUrl ":"'. $ row ["goodsurl"]. '"," brandName ":"'. $ row
["Brandname"]. '"," brandUrl ":"'. $ row ["brandurl"]. '"},';
$ I ++;
}
If ($ I> 0) {$ arrystr = substr ($ arrystr, 0, $ arrystr. lenght-1 );}
If you write
$ A = '{"status": "1", "result ":['. $ arrystr. '], "moreUrl ":"'. $ moreurl. '"}';
AJAX returns {"status": "1", "result": [], "moreUrl": "http :\/\/"}
Result is empty
If this is the case, the write operation is normal.
// $ A = '{"status": "1", "result": [{"id": "1", "title ": "moisturizing body lotion is really good, moisturizing skin elasticity", "goodsTitle": "moisturizing body lotion is really good, moisturizing skin elasticity", "price": "59.9", "imgUrl ": "http: // sadas213/", "goodsUrl": "http: // uploads/allimg/c131205/
13V23912150-114L_lit.jpg "," brandName ":" "," brandUrl ":" http: // dsadasdas/"},{" id ":" 2 "," title ": "moisturizing
222 "," goodsTitle ":" moisturizing"
222 "," price ":" 59.9 "," imgUrl ":" http: // sadas213/"," goodsUrl ":" http: // uploads/allimg/c131205
/13V23912150-
114L_lit.jpg "," brandName ":" "," brandUrl ":" http: // dsadasdas/"}]," moreUrl ":" http://jianfei.ecoo.com.cn/shuig
Uo /"}';
$ A = iconv ("gbk", "UTF-8", $ );
$ A = json_decode ($ a, true );
Echo json_encode ($ );
Thank you for your advice!
Reply to discussion (solution)
$ R ['A'] = 123; echo json_encode ($ r); // Get {"a": 123} $ a [] = $ r; $ a [] = $ r; $ a [] = $ r; echo json_encode ($ a); // Get [{"a": 123 },{ "": 123 },{ "a": 123}]
Do you know how to write it?
Although php json Functions only support UTF-8 encoding, you can ask the database to return UTF-8 encoded data.
Hello, moderator. I have changed the code to this, but it still doesn't work. net Php is too bad for me. thank you for your guidance.
$ A = array ();
While ($ row = $ dsql-> GetArray ()){
$ A [] = $ row;
}
$ A = '{"status": "1", "result ":'. json_encode ($ ). ', "moreUrl ":"'. $ moreurl. '"}';
$ A = iconv ("gbk", "UTF-8", $ );
$ A = json_decode ($ a, true );
Echo json_encode ($ );
AJAX returns {"status": "1", "result": [], "moreUrl": "http :\/\/"}
Result is empty
1. what database are you using? Not Access, right?
2. if you cannot get the database to return UTF-8 encoded data
function gtou($s) { return iconv('gbk', 'utf-8', $s); }$a=array();while($row = $dsql->GetArray()) { $a[]= array_map('gtou', $row); }
3. construct output data in this way
$res = array( 'status' => '1', 'result' => $a, 'moreUrl' => $moreurl,);echo join_encode($res);
The moderator is right when writing and outputting data.
However
AJAX returns {"status": "1", "result": [], "moreUrl": "http :\/\/"}
Result is empty
My QQ 272718467 would you like to add my QQ for guidance or follow me?
In this way, AJAX can directly return the data read from the database and receive the result.
// $ A = '{"status": "1", "result": [{"id": "1", "title ": "moisturizing body lotion is really good, moisturizing skin elasticity", "goodsTitle": "moisturizing body lotion is really good
Very hydrating skin with bullet
Sex "," price ":" 59.9 "," imgUrl ":" http: // sadas213/"," goodsUrl ":" http: /// uploads/allimg/c131205/
13V23912150-114L_lit.jpg "," brandName ":" "," brandUrl ":" http: // dsadasdas/"},{" id ":" 2 "," title ": "moisturizing
222 "," goodsTitle ":" moisturizing"
222 "," price ":" 59.9 "," imgUrl ":" http: // sadas213/"," goodsUrl ":" http: // uploads/allimg/c131205
/13V23912150-114L_lit.jpg "," brandName ":" "," brandUrl ":" http: // dsadasdas/"}]," moreUrl ":" http: // shuig
Uo /"}';
I am a mysql database
$ JsonStr = '[{"id": "1", "name": "\ u5f20 \ u96ea \ u6885", "age": "27", "subject ": "\ u8ba1 \ u7b97 \ u673a \ u79d1 \ u5b66 \ u4e0e \ u6280 \ u672f" },{ "id": "2", "name ": "\ u5f20 \ u6c9b \ u9716", "age": "21", "subject": "\ u8f6f \ u4ef6 \ u5de5 \ u7a0b"}] '; // The parsed string can only be used? Introduction ?, Cannot be used? Introduction? $ Json = json_decode ($ JsonStr, TRUE); echo'',var_dump($Json),'
'; $ Array = array ('a' => 'A',' B '=> 2); $ a = json_encode ($ array); echo'',var_dump($a),'
'; $ A = serialize ($ array); echo'',var_dump($a),'
'; $ A = unserialize ($ a); echo'',var_dump($a),'
'; Die ();
Sibang, Hello, I have not found any double quotation marks. the problem still persists.
I am a php + ajax + json
Thank you for your support.
Path error during AJAX request
No other problems
Close the post !!!
Well, it seems you should be careful.