JSON
JSONObject jsonObject = jsonArray.getJSONObject(i);//for (int i = 0; i < jsonArray.length(); i++) {
AddressBean shopInfo = gson.fromJson(json, AddressBean.class);
JSON.parseArray(json, AddressBean.class);
JSON.parseObject(json, AddressBean.class);
List<AddressBean> shops = gson.fromJson(json, new TypeToken<List<AddressBean>>() {}.getType());
JSONArray jsonArray = new JSONArray(result);
for (int i = 0; i < jsonArray.length(); i++) {
AddressBean addressBean = (AddressBean) UtilsJson.fromJson(jsonArray.get(i).toString(), AddressBean.class);
mAddressBeans.add(addressBean);
}
AddressBean
二:
JSONArray jsonArray = new JSONArray(result);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
if (jsonObject != null) {
int id = jsonObject.optInt("id");
String name = jsonObject.optString("user_id");
double price = jsonObject.optDouble("city");
AddressBean address = new AddressBean (id, user_id, city);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
三:
解析JSON数据
Gson gson = new Gson();
AddressBean address = gson.fromJson(json, AddressBean .class);
四:
Gson gson = new Gson();
List<AddressBean> shops = gson.fromJson(json, new TypeToken<List<AddressBean>>() {}.getType());