How to parse Json data from URL?which contains num

2019-09-20 13:37发布

i am having a issue of parsing JSON data i followed this link..

over there it has parsing data images description..

and i also refereed this in stack over flow a guy who is having same issue but no correct answer.. How to Parse JSONarray inside JSONarray in android? and How to display Image from URL?

we can say just extention of the above questions..

its not a duplicate that guy is also same problem no answer..

i have a data like below

{
"request": "ok",
"query": {
    "result": [
        {
            "site": [
                {
                    "latest": [
                        {
                            "id": "2eaQy8Ow",
                            "data": "1/1/2014"
                        }
                    ]
                }
            ],
            "flag": [
                "http://www.simplydecoded.com/wp-content/uploads/2013/02/Telangana2.jpg"
            ]
        }
    ]
   }
  }

i am using below code for parsing

JSONArray json_query_flag = c.getJSONArray("flag");


JSONArray json_query_site=c.getJSONArray("site");
System.out.println("looping json_query_site");
for (int j = 0; j < c.length(); j++) {
System.out.println("looping json_query_site[" + j +"]" + "json_query_site.length() -->" + json_query_site.length());

if (j <json_query_site.length()) {

HashMap<String, String> map1 = new HashMap<String, String>();
JSONObject sd = json_query_site.getJSONObject(j);

// get latestoffers
JSONArray json_latest = sd.getJSONArray("latest");
System.out.println(json_latest.toString());

for (int k = 0; k < json_latest.length(); k++) {

HashMap<String, String> map2 = new HashMap<String, String>();
JSONObject e = json_latest.getJSONObject(k);

My problem is that i am not getting the latest and flag.. may be parsing problem..

2条回答
我命由我不由天
2楼-- · 2019-09-20 13:57

TRy this..

JSONObject JObj = new JSONObject(response);
JSONObject query = JObj.getJSONObject("query");
JSONArray result = query.getJSONArray("result");
for (int i = 0; i < result.length(); i++) {
        JSONObject jobj = result.getJSONObject(i);
        JSONArray site = jobj.getJSONArray("site");
            for (int j = 0; j < site.length(); j++) {
                JSONObject sitobj = site.getJSONObject(j);
                JSONArray latest = sitobj.getJSONArray("latest");
                    for (int k = 0; k < latest.length(); k++) {
                         JSONObject lateobj = latest.getJSONObject(k);
                         System.out.println("id : "+lateobj.getString("id"));
                    }
            }
        JSONArray flag = jobj.getJSONArray("flag");
        for (int l = 0; l < flag.length(); l++) {
            System.out.println("urls : "+flag.getString(l));
        }
}
查看更多
▲ chillily
3楼-- · 2019-09-20 14:14

Hellow man thanks for understanding the problem please follow this post for the till your site and latest..

it solved I am getting text.. but problem with images I think you have flag.. for that you need to change your Listviewadapter.java file. so that images will appear

change this like

String strflag = resultp.get(Mainactivity.IMAGES);
    if(strflag != null)
        imageLoader.DisplayImage(strflag, flag);
    else
        imageLoader.DisplayImage("http://www.butterentals.com/graphics/no_image.jpg", flag);

so that I will be done.

查看更多
登录 后发表回答