JSONArray与JSONObject的使用

主要是使用Array返回指定数据格式。

使用代码样例如下:

JSONArray jsonArrayS = new JSONArray();

JSONObject typeJson = new JSONObject();

String houseType = "住宅";

typeJson.put("houseType", houseType);

JSONArray NameArray = new JSONArray();
for (i=0 i<10 i++) {
    JSONObject jsonName = new JSONObject();
    jsonName .put("Names", "张三");
    NameArray.add(jsonName); 
}

//倒序输出
List<JSONObject> NameList = JSONArray.parseArray(NameArray.toJSONString(), JSONObject.class);
Collections.reverse(NameList);
JSONArray jsonNamesdataArray = JSONArray.parseArray(NameList.toString());

typeJson.put("nameJson" , jsonNamesdataArray);

jsonArrayS.add(typeJson);

猜你喜欢

转载自blog.csdn.net/qq_41992943/article/details/106681017