我想知道json的格式是什么,因为看起来php和android有两种不同的类型。
编码php时,它看起来像这样:
{"id":8435,"name":"Sears"}
{"id":8436,"name":"Sears Appliance Services"}
但是当我尝试在android中解码时。它是android中的一个大字符串(因为它只是查看php页面的源代码)。
这是代码:
腓:
echo json_encode($ results [$ i]);
Android:
url = new URL("site");
String param = "arg1=" + URLEncoder.encode("value1", "UTF-8");
conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setFixedLengthStreamingMode(param.getBytes().length);
conn.setRequestProperty("Content-Type","application/x-www-form- urlencoded");
PrintWriter out = new PrintWriter(conn.getOutputStream());
out.print(param);
out.close();
InputStream is = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String s;
while ((s = reader.readLine()) != null) {
result += s;
}
JSONObject jObject = new JSONObject(result);