Array json Parsing Method

Source: Internet
Author: User

Array json Parsing Method

An error is reported directly when jsonObject is used because json of the array type cannot be parsed.

Json data such:

[{"Id": "1000142", "name": "\ u5168 \ u90e8 \ u7c7b \ u578b", "subMenu": [{"id": "1000135 ", "name": "\ u591a \ u5a92 \ u4f53 \ u8bbe \ u8ba1" },{ "id": "1000137", "name": "java \ u5f00 \ u53d1 "}, {"id": "1000138", "name": "\ u524d \ u7aef \ u5f00 \ u53d1" },{ "id": "1000139", "name ": "php \ u5f00 \ u53d1" },{ "id": "1000140", "name": "IOS \ u5f00 \ u53d1" },{ "id": "1000141 ", "name": "android \ u5f00 \ u53d1"}] },{ "id": "1000143", "name": "\ u5168 \ u90e8 \ u7b49 \ u7ea7 ", "subMenu": [{"id": "1000146", "name": "\ u9ad8 \ u7ea7" },{ "id": "1000145", "name ": "\ u4e2d \ u7ea7" },{ "id": "1000144", "name": "\ u530d \ u7ea7"}]

Solution:

Type listmenu = new TypeToken<ArrayList<ListMenu>>(){}.getType();List<ListMenu> menuPage=new Gson().fromJson(json, listmenu);



How to parse json arrays similar to MAP types?

Json is generally parsed using an existing library, and no one parses it by themselves. LZ goes to the next one on the Internet.
 
How to parse json into an array

Each element in the province array is a map record province name and province City
The city is also a map to record the city name and the city's county layer-by-layer nesting, and finally converted to the json format toString () Output Using JSONObject
 

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.