How to parse JSON data with no key in Android

Source: Internet
Author: User
Tags json

Sina Weibo has some of the JSON data as follows, you will find that this is a number of groups, but the array does not have a key, the object in the array also has no key. How to resolve it? Fastjson encounters this nameless array set nameless objects also report an exception. It is therefore recommended that native JSON parsing be used.

First, the question:

Second, the Analytic code:

 Com.ht.weibo.weibomodel; 
Com.sina.weibo.sdk.openapi.models.Status;
Org.json.JSONArray;
Org.json.JSONException; Org.json.JSONObject; Java.util.ArrayList;
{
arraylist<status> statuses;
Arraylist<status> () {
statuses;
}
(arraylist<status> statuses) {
. statuses = statuses;

(String json) {
(JSON!=) {
{
Jsonarray array = Jsonarray (JSON);
statuses = arraylist<> ();
(i =; I < Array.Length (); i++) {
Jsonobject jsonobject = Array.getjsono Bject (i);
Status Status = Status.parse (Jsonobject);
Statuses.add (status);
}
}
(Jsonexception e) {
E.printstacktrace ();

}
}
}

For the other solution of this problem, specific reference: (not practice)

Http://zm8.sm-img2.com/?src=http%3A%2F%2Fsegmentfault.com%2Fq%2F1010000000174990&uid= 0b4cd023903934907ec4a15ea96326f5&hid=29ae2ef764df9a92491d377a505210ed&pos=1&cid=9&time= 1433608784138&from=click&restype=1&pagetype=0000004000000402&bu=web&query=json%e8%a

How do I get the key value of the JSON data dynamic change?

Http://www.apkbus.com/android-114271-1-1.html

There is a Jsonobject.keys () method. The return value is the iterator

        Iterator<string>  = json. ();
Because there is only one object, you do not have to do more in-depth iterations

Four

JSON parsing, if some of the fields or objects are opt, then you need to do an empty judgment

Related Article

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.