somebodyoneday 2019-12-07
问题1:类似String s = "[ { },{ },{ } ]";这种结构的解析
方法一:
Gson gson =newGson();
List<Object> mList = gson.fromJson(result, newTypeToken<List<Object>>(){}.getType());
方法二:
1.将该String字符串转为JSONArray
JSONArray objects =JSONArray.parseArray(result);
2.遍历这个JSONArray,将每个JSONArray转为对应的实体
for(intj=0;j<objects.size();j++){
JSONObject jsonObject = objects.getJSONObject(j);
Object mObject= JSONObject.parseObject(jsonObject.toString(),Object.class);
mList.add(mObject); //添加到与之对应的list集合
}
parserStr=“无key的JSON”
JSONArray jsonArray = new JSONArray(parserStr);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String pStr = jsonObject.getString("ITEM_NAME");
String pStr = jsonObject.getString("NAME");
String pStr = jsonObject.getString("ITEM");