-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonTest.java
More file actions
29 lines (25 loc) · 779 Bytes
/
Copy pathJsonTest.java
File metadata and controls
29 lines (25 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.json;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
* @Auther: Administrator
* @Date: 2019\7\10 0010 23:31
* @Description:
*/
public class JsonTest {
public static void main(String[] args) {
JSONArray jsonArray=new JSONArray();
JSONObject jsonObject=new JSONObject();
jsonObject.put("name","lin");
jsonObject.put("age",100);
jsonArray.add(jsonObject);
// for(int i=0;i<jsonArray.size();i++){
// JSONObject jsonobject=jsonArray.getJSONObject(i);
// System.out.println(jsonobject.getString("name"));
// }
for (Object user:jsonArray){
String name= ((JSONObject) user).getString("name");
System.out.println(name);
}
}
}