superxff

一、JSON字符串取出里面的数据。集合形

String json = "[{a:\"11\",b:\"22\"},{b:\"22\"},{c:\"33\"}]";
//将字符串转换成json集合
JSONArray parseArray = JSONObject.parseArray(json);
//遍历json集合
for (int i = 0; i < parseArray.size(); i++) {
	JSONObject jsonObject = parseArray.getJSONObject(i);
	String str1 = (String) jsonObject.get("a");
	String str2 = (String) jsonObject.get("b");
	System.out.println("str1==="+str1+"==="+str2);
}

二、JSON字符串取出里面的数据。

String json = "{a:\"11\",b:\"22\",c:\"33\",d:\"44\"}";
//将字符串转换成json
JSONObject jsonObject = JSONObject.parseObject(json);
//取json数据
System.out.println("json==="+jsonObject.getString("a"));
System.out.println("json==="+jsonObject.getString("b"));
System.out.println("json==="+jsonObject.getString("c"));

  

分类:

技术点:

相关文章:

  • 2021-11-20
  • 2021-11-20
  • 2021-11-20
  • 2021-11-20
  • 2021-11-20
  • 2021-11-17
  • 2021-11-17
  • 2021-11-17
猜你喜欢
  • 2021-11-20
  • 2021-12-04
  • 2021-11-20
  • 2021-11-17
  • 2021-11-20
  • 2021-11-17
  • 2018-08-07
相关资源
相似解决方案