json后台的一些处理方式

package com.test;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class json {


public static void main(String[] args) throws JSONException {


//String json1 = "{'name':'曹欢','age':21}";
////JSONObject jsonObject = new JSONObject(json1);
//JSONObject object = new JSONObject(json1);
//String name = object.getString("name");//得到json对象里的属性值
//Integer age = object.getInt("age");
//System.out.println(name);
//System.out.println(age);
//String array = "[{'age':21,'name':'曹欢'},{'age':27,'name':'笑话'}]";
//JSONArray array1 = new JSONArray(array);
//String name2 = array1.getJSONObject(0).getString("name");//得到json数组里的某个对象的属性值
// System.out.println(name2);

String josnString = "[{'name':'曹欢','age':21},{'name':'曹欢','family':[{'name':'asd','age':23}]},{'name':'曹娟','age':23}]";
JSONArray array = new JSONArray(josnString);
System.out.println(array.getJSONObject(1).getJSONArray("family").getJSONObject(0).getString("name"));
//for (int i = 0; i < array.length(); i++) {
//
//JSONObject object = array.getJSONObject(i);
//if(i == 1)
//{
//
//}
//String name = object.getString("name");
//Integer age = object.getInt("age");
//}

}

}

你可能感兴趣的:(json)