This is part of the code:
$client = M ("client");
$data = $client->where (' user_id = '. $user _id)->select ();
if ($data = = False | | $data = = NULL)
{
/* Query Error */
$str = Array (
' Status ' = ' ERROR ',
' msg ' = ' query error ',
' content ' = ' null '
);
$this->ajaxreturn ($STR);
}
Else
{
/* Query Successful */
$str = Array (
' Status ' = ' success ',
' msg ' = ' query succeeded ',
' Content ' = $data
);
$this->ajaxreturn ($STR);
}
Note: PHP compare two strings try not to use = = to compare, there will be unexpected consequences, try to use strcmp to compare, when the result is 0 when the expression wants to wait.
Here are two kinds of results:
1, the existence of users:
{"Status": "Success", "MSG": "\u67e5\u8be2\u6210\u529f", "content": [{"client_id": "000003", "Client_name": "\u5f90\ u5229\u5175 "," Client_phone ":" 18813752547 "," client_address ":" \u5e7f\u4e1c\u97f6\u5173\u7fc1\u6e90 "," Client_ Picture ":" Http:\/\/www.baidu.com "," user_id ":" 18813752547 "},{" client_id ":" 000002 "," Client_name ":" \u5f90\u5229\ u5175 "," Client_phone ":" 18813752547 "," client_address ":" \u5e7f\u4e1c\u97f6\u5173\u7fc1\u6e90 "," Client_picture ":" Http:\/\/www.baidu.com "," user_id ":" 18813752547 "},{" client_id ":" 000001 "," Client_name ":" \u5f90\u5229\u5175 "," Client_phone ":" 18813752547 "," client_address ":" \u5e7f\u4e1c\u97f6\u5173\u7fc1\u6e90 "," client_picture ":" Http:\/\ /www.baidu.com "," user_id ":" 18813752547 "},{" client_id ":" 000000 "," Client_name ":" \u5f90\u5229\u5175 "," Client_ Phone ":" 18813752547 "," client_address ":" \u5e7f\u4e1c\u97f6\u5173\u7fc1\u6e90 "," client_picture ":" http:\/\/ Www.baidu.com "," user_id ":" 18813752547 "},{" client_id ":" 000004 "," Client_name ":" \u5f90\u5229\u5175 "," Client_phone ":" 18813752547 "," client_addresS ":" \u5e7f\u4e1c\u97f6\u5173\u7fc1\u6e90 "," client_picture ":" Http:\/\/www.baidu.com "," user_id ":" 18813752547 "},{ "client_id": "000005", "Client_name": "\u5f90\u5229\u5175", "Client_phone": "18813752547", "client_address": "\u5e7f\ U4e1c\u97f6\u5173\u7fc1\u6e90 "," client_picture ":" Http:\/\/www.baidu.com "," user_id ":" 18813752547 "}]}
2, does not exist the user's:
{"Status": "Error", "MSG": "\u67e5\u8be2\u9519\u8bef", "content": "Null"}
I believe we all care about a problem: How does the Android client parse this JSON format? Let me answer for you:
Assuming that the Android client will save the content read from the server in Buider, then:
Jsonobject Jsonobject1 = new Jsonobject (builder.tostring ()). Getjsonobject ("status");
Jsonobject jsonobject2 = new Jsonobject (builder.tostring ()). Getjsonobject ("msg");
Jsonobject jsonobject3 = new Jsonobject (builder.tostring ()). Getjsonobject ("content");
String client_id = jsonobject3.getstring ("client_id");
String client_name = jsonobject3.getstring ("Client_name");
............
One analogy.
For other formats JSON parsing, self-search online method.
Please refer to this: http://www.cnblogs.com/cpcpc/archive/2011/07/22/2122989.html
On the method of converting string into JSON array in thinkphp