The great God helps Java parse JSON

Source: Internet
Author: User

============ Problem Description ============


{
"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
}

============ Solution 1============


Use Android-provided jsonarray data = new Jsonarray (your string), and then traverse the data to jsonobject Jsonobject = Jsonarray.getjsonobject (i); Gets the value int adkind = jsonobject.getint (field name) based on the field;

============ Solution 2============


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 ();} 

============ Solution 3============


[

Reference 3 Floor wlianghe00 's reply:
try {jsonobject Jo = new Jsonobject (JSON); int status = Jo.optint ("status"); String address = jo.optstring ("Address");Jsonobject jo_point = Jo.optjsonobject ("point"); Jo changed to 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 ();}

============ Solution 4============


Such a standard format, with Jsonobject

The great God helps Java parse JSON

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.