那位大神帮忙JAVA解析JSON

刺心_ 2014-07-28 11:48:03
加精
{
"address": "CN|\u5e7f\u4e1c|\u6df1\u5733|None|UNICOM|None|None",
"content": {
"address": "\u5e7f\u4e1c\u7701\u6df1\u5733\u5e02",
"address_detail": {
"city": "\u6df1\u5733\u5e02",
"city_code": 340,
"district": "",
"province": "\u5e7f\u4e1c\u7701",
"street": "",
"street_number": ""
},
"point": {
"x": "114.02597366",
"y": "22.54605355"
}
},
"status": 0
}
...全文
1736 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
gson那么方便,你看看文档
qq_14834983 2016-01-11
  • 打赏
  • 举报
回复
package net.sourceforge.simcpux2.ddd; public class MD5 { /** * address : CN|广东|深圳|None|UNICOM|None|None * content : {"address":"广东省深圳市","address_detail":{"city":"深圳市","city_code":340,"district":"","province":"广东省","street":"","street_number":""},"point":{"x":"114.02597366","y":"22.54605355"}} * status : 0 */ private String address; /** * address : 广东省深圳市 * address_detail : {"city":"深圳市","city_code":340,"district":"","province":"广东省","street":"","street_number":""} * point : {"x":"114.02597366","y":"22.54605355"} */ private ContentEntity content; private int status; public void setAddress(String address) { this.address = address; } public void setContent(ContentEntity content) { this.content = content; } public void setStatus(int status) { this.status = status; } public String getAddress() { return address; } public ContentEntity getContent() { return content; } public int getStatus() { return status; } public static class ContentEntity { private String address; /** * city : 深圳市 * city_code : 340 * district : * province : 广东省 * street : * street_number : */ private AddressDetailEntity address_detail; /** * x : 114.02597366 * y : 22.54605355 */ private PointEntity point; public void setAddress(String address) { this.address = address; } public void setAddress_detail(AddressDetailEntity address_detail) { this.address_detail = address_detail; } public void setPoint(PointEntity point) { this.point = point; } public String getAddress() { return address; } public AddressDetailEntity getAddress_detail() { return address_detail; } public PointEntity getPoint() { return point; } public static class AddressDetailEntity { private String city; private int city_code; private String district; private String province; private String street; private String street_number; public void setCity(String city) { this.city = city; } public void setCity_code(int city_code) { this.city_code = city_code; } public void setDistrict(String district) { this.district = district; } public void setProvince(String province) { this.province = province; } public void setStreet(String street) { this.street = street; } public void setStreet_number(String street_number) { this.street_number = street_number; } public String getCity() { return city; } public int getCity_code() { return city_code; } public String getDistrict() { return district; } public String getProvince() { return province; } public String getStreet() { return street; } public String getStreet_number() { return street_number; } } public static class PointEntity { private String x; private String y; public void setX(String x) { this.x = x; } public void setY(String y) { this.y = y; } public String getX() { return x; } public String getY() { return y; } } } }
joney_hy 2014-10-08
  • 打赏
  • 举报
回复
一楼的方法是最好最简单的,gson简单易学
梦_影 2014-09-26
  • 打赏
  • 举报
回复
你这个数据还是比较少的,所以直接用jsonobject解析还可以,但是多的话,还是用gson解析简单点
qq_18397929 2014-07-31
  • 打赏
  • 举报
回复
吾非名家 2014-07-30
  • 打赏
  • 举报
回复
刚学了下。。发现用gson来解析真的不难。。。结贴给分吧。。
teemai 2014-07-29
  • 打赏
  • 举报
回复
这么标准的格式,用JSONObject
老李家的小二 2014-07-29
  • 打赏
  • 举报
回复
结贴,送分吧
sunbo624 2014-07-29
  • 打赏
  • 举报
回复
有现成的工具包 我知道的就 jackson fastjson jsonlib gson 还求代码?
刺心_ 2014-07-29
  • 打赏
  • 举报
回复
3楼4楼有一处写错啦。但还是很感谢。我改正过来。
吾非名家 2014-07-29
  • 打赏
  • 举报
回复
我也需要这个。。关注此贴。。。
lionfresh 2014-07-29
  • 打赏
  • 举报
回复
实例代码

JSONTokener jsonTokener = new JSONTokener(json);
JSONObject jsonObject = (JSONObject) jsonTokener.nextValue();
JSONArray array = jsonObject.getJSONArray("contacts");
JSONObject object = array.getJSONObject(0);
String name = object.getString("name");
Utopia 2014-07-29
  • 打赏
  • 举报
回复
[
引用 3 楼 wlianghe00 的回复:
try {
			JSONObject jo = new JSONObject(json);
			int status = jo.optInt("status");
			String address = jo.optString("address");
			
			JSONObject jo_point = jo.optJSONObject("point"); jo换成jo_content 
			String x = jo_point.optString("x");
			String y = jo_point.optString("y");
			
			JSONObject jo_content = jo.optJSONObject("content");
			String content_address = jo_content.optString("address");
			
			JSONObject jo_detail = jo_content.optJSONObject("address_detail");
			String city = jo_detail.optString("city");
			int code = jo_detail.optInt("city_code");
			String district = jo_detail.optString("district");
			String province = jo_detail.optString("province");
			String street = jo_detail.optString("street");
			String street_number = jo_detail.optString("street_number");
		} catch (JSONException e) {
			e.printStackTrace();
		}
Utopia 2014-07-29
  • 打赏
  • 举报
回复
try {
			JSONObject jo = new JSONObject(json);
			int status = jo.optInt("status");
			String address = jo.optString("address");
			
			JSONObject jo_point = jo.optJSONObject("point");
			String x = jo_point.optString("x");
			String y = jo_point.optString("y");
			
			JSONObject jo_content = jo.optJSONObject("content");
			String content_address = jo_content.optString("address");
			
			JSONObject jo_detail = jo_content.optJSONObject("address_detail");
			String city = jo_detail.optString("city");
			int code = jo_detail.optInt("city_code");
			String district = jo_detail.optString("district");
			String province = jo_detail.optString("province");
			String street = jo_detail.optString("street");
			String street_number = jo_detail.optString("street_number");
		} catch (JSONException e) {
			e.printStackTrace();
		}
逍遥笑 2014-07-29
  • 打赏
  • 举报
回复
使用android提供的JSONArray data = new JSONArray(你的字符串);,再遍历这个data,转为JSONObject jsonObject = jsonArray.getJSONObject(i);在根据字段获取值int adkind = jsonObject.getInt(字段名);
qq_18617041 2014-07-29
  • 打赏
  • 举报
回复
你说的能否打开
subanxianc 2014-07-29
  • 打赏
  • 举报
回复
一直用GSON,挺好用的
梅烦恼 2014-07-29
  • 打赏
  • 举报
回复
开晚了,已经有人给答案了。
只是_曾经 2014-07-29
  • 打赏
  • 举报
回复
JSONObject足矣。不知道你是抱着什么心态发问的
哎,真难 2014-07-29
  • 打赏
  • 举报
回复
用Gson,定义成实体类来解析呗,,,

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧