1、json格式字符串

2、将json格式字符串转换成json格式
String str = "{ \"people\": [\n" +"\n" +"{ \"firstName\": \"Brett\", \"lastName\":\"McLaughlin\", \"email\": \"aaaa\" },\n" +"\n" +"{ \"firstName\": \"Jason\", \"lastName\":\"Hunter\", \"email\": \"bbbb\"},\n" +"\n" +"{ \"firstName\": \"Elliotte\", \"lastName\":\"Harold\", \"email\": \"cccc\" }\n" +"\n" +"]}";
JSONObject jsonObject = JSONObject.fromObject(str);
System.out.println("jsonObject"+jsonObject);

3、获取json格式数据中值
JSONArray people1 = jsonObject.getJSONArray("people");
System.out.println("people1====22222======="+people1);

4、获取到的值是一个数组对象,获取素组中的每一个对象
for(Iterator iterator = people1.iterator();;){ if(iterator.hasNext()){JSONObject job = (JSONObject) iterator.next();System.out.println("输出每个对象"+job);}
}

5、测试类
```java
package org.iam.commpoment.timertask.demo;import net.sf.json.JSONArray;
import net.sf.json.JSONObject;import java.util.Iterator;
public class Test {public static void main(String[] args) {
String str = "{ \"people\": [\n" +"\n" +"{ \"firstName\": \"Brett\", \"lastName\":\"McLaughlin\", \"email\": \"aaaa\" },\n" +"\n" +"{ \"firstName\": \"Jason\", \"lastName\":\"Hunter\", \"email\": \"bbbb\"},\n" +"\n" +"{ \"firstName\": \"Elliotte\", \"lastName\":\"Harold\", \"email\": \"cccc\" }\n" +"\n" +"]}";System.out.println("str====1111111====="+str);JSONObject jsonObject = JSONObject.fromObject(str);System.out.println("jsonObject"+jsonObject);JSONArray people1 = jsonObject.getJSONArray("people");System.out.println("people1====22222======="+people1);JSONArray jsonArray = JSONArray.fromObject(people1);System.out.println("jsonArray=======333333========"+jsonArray);for(Iterator iterator = people1.iterator();;){ if(iterator.hasNext()){JSONObject job = (JSONObject) iterator.next();System.out.println("输出每个对象"+job);}}
}}
