欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

json字符串解析  

程序员文章站 2022-06-07 16:25:53
...

 

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
String str = "{\"name\":\"zhangsan\",\"password\":\"zhangsan123\",\"email\":\"10371443@qq.com\"}";
JSONObject json = JSONObject.parseObject(str);
System.out.println(json.getString("name"));


String jsonString = "[{\"name\":\"zhangsan\",\"password\":\"zhangsan123\",\"email\":\"10371443@qq.com\"}"
	+ ",{\"name\":\"lisi\",\"password\":\"lisi123\",\"email\":\"1435123@qq.com\"}]";
JSONArray jsonArray = JSONArray.parseArray(jsonString);
for(int i = 0 ;i < jsonArray.size() ; i++){
    System.out.println("name = "+jsonArray.getJSONObject(i).getString("name"));
    System.out.println("password = "+jsonArray.getJSONObject(i).getString("password"));
    System.out.println("email = "+jsonArray.getJSONObject(i).getString("email"));
}