我之前一直不知道怎么解析和生成json数据的 今天在这里终于知道了应该怎么写!
{
"cat":"it",
"language":[{"id":1,"name":"张三"},{"id":1,"name":"张三"}]
}
一个简单的 对象 对象和数组 一起的
// 从服务器解析接送数据
// // JSONObject root1=data.JSONObject;
// JSONObject root = new JSONObject();
// try {
// root.getString("cat");
//
// JSONArray array = root.getJSONArray("language");
// for (int i = 0; i < array.length(); i++) {
// JSONObject len=new JSONObject();
// len.get("id");
// len.getString("name");
// }
//
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// 把一个对象 一个数组 封装成json格式
// JSONObject root=new JSONObject();
// try {
// root.put("cat", "id");
//
// JSONObject len=new JSONObject();
// len.put("id", 1);
// len.put("name", "java");
//
// JSONArray ja=new JSONArray();
// ja.put(len);
// root.put("language", ja);
//
// } catch (JSONException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }