how to fix type mismatch json exception while parsing a json url in Android? -
i trying retrieve json
data using url
. json array posted below. getting type mismatch json exception. can 1 guide me step step going wrong? error logs posted below.
secondly, please tell me whether json parsing using url same json parsing using php server database.
url : http://166.62.17.208/json_preferencess.aspx
"items": [ { "id": "11", "item_id": "123", "item_name": "chicken cream soup", "price": "8", "currency": "aed", "category": "soup", "description": "creamy chicken soup garnish & side helpings", "unit": "2", "food_type": "non", "image_large": "/images_large/chickensoup.jpg", "image_thumb": "/images_large/chickensoup.jpg", "timestamp": "6/23/2014 9:49:43 pm", "promotion": "", "item_name_arabic": "حساء الطماطم", "item_name_russian": "", "currency_arabic": "درهم", "currency_russian": "", "description_arabic": "حساء الطماطم", "description_russian": "", "note": "", "nutritional_info": "", "extrafield_1": "", "extrafield_2": "", "preferncess": [ "no salt", "extra sugar" ], "preferncess_ids": [ "1", "2" ], "price": [ "4", "5" ], "preferncess_arabic": [ "لا الملح", "سكر اضافية" ] } ], "category_timestamp": "6/24/2014 1:05:28 pm", "questions": [ { "q_id": "1", "q_question": "how rate our menu ?", "q_option1": "excellent", "q_option2": "very good", "q_option3": "good", "q_option4": "bad", "q_option5": "terrible", "timestamp": "9/12/2013 3:31:55 pm", "q_status": "1" }, ],
mainactivity.class
string jsonstr = sh.makeservicecall(url, servicehandler.get); log.d("response: ", "> " + jsonstr); if (jsonstr != null) { try { jsonobject jsonobj = new jsonobject(jsonstr); // getting json array node //items = jsonobj.getjsonarray(tag_contacts); log.i("json node",""+jsonobj); // looping through contacts (int = 0; < items.length(); i++) { jsonobject c = items.getjsonobject(i); string id = c.getstring("id"); } }
error logs
06-27 06:55:50.154: w/system.err(2192): org.json.jsonexception: value [{"questions":[{"q_id":"1","q_question":"how rate our menu ?","q_status":"1","q_option5":"terrible","q_option3":"good","q_option4":"bad","q_option2":"very good","q_option1":"excellent","timestamp":"9\/12\/2013 3:31:55 pm"},{"q_id":"2","q_question":"how rate our presentation, taste , quality of food ?","q_status":"1","q_option5":"terrible","q_option3":"good","q_option4":"bad","q_option2":"very good","q_option1":"excellent","timestamp":"9\/12\/2013 3:31:55 pm"},{"q_id":"3","q_question":"how rate friendliness our staff members ?","q_status":"1","q_option5":"terrible","q_option3":"good","q_option4":"bad","q_option2":"very good","q_option1":"excellent","timestamp":"9\/12\/2013 3:31:55 pm"},{"q_id":"4","q_question":"how rate our staff's performance , service?","q_status":"1","q_option5":"terrible","q_option3":"good","q_option4":"bad","q_option2":"very good","q_option1":"excellent","timestamp":"9\/12\/2013 3:31:55 pm"},{"q_id":"5","q_question":"how rate value money ?","q_status":"1","q_option5":"terrible","q_option3":"good","q_option4":"bad","q_option2":"very good","q_option1":"excellent","timestamp":"9\/12\/2013 3:31:55 pm"}],"categories":[{"categoryarabicname":"سلطة خضراء","catid":"0","categoryshortname":"salads","categoryname":"salads"},{"categoryarabicname":"المزة","catid":"1","categoryshortname":"mezzah","categoryname":"mezzah"},{"categoryarabicname":"الطبق الرئيسي","catid":"2","categoryshortname":"main-course","categoryname":"main course"},{"categoryarabicname":"معكرونة","catid":"3","categoryshortname":"pasta","categoryname":"pasta"},{"categoryarabicname":"مثوبة","catid":"4","categoryshortname":"deserts","categoryname":"deserts"},{"categoryarabicname":"حساء","catid":"5","categoryshortname":"soup","categoryname":"soup"}],"question_timestamp":"9\/12\/2013 3:31:55 pm","items":[{"image_large":"\/images_large\/chickensoup.jpg","promotion":"","food_type":"non","item_name":"chicken cream soup","unit":"2","id":"11","nutritional_info":"","description_arabic":"حساء الطماطم","image_thumb":"\/images_large\/chickensoup.jpg","preferncess":["no salt","extra sugar"],"extrafield_1":"","extrafield_2":"","currency":"aed","description_russian":"","description":"creamy chicken soup garnish & side helpings","preferncess_ids":["1","2"],"item_name_russian":"","currency_russian":"","note":"","item_id":"123","preferncess_arabic":["لا الملح","سكر اضافية"],"timestamp":"6\/23\/2014 9:49:43 pm","category":"soup","price":["4","5"],"currency_arabic":"درهم","price":"8","item_name_arabic":"حساء الطماطم"},{"image_large":"\/images_large\/pasta.jpg","promotion":"","food_type":"non","item_name":"pasta napolitan","unit":"20","id":"12","nutritional_info":"","description_arabic":"حساء الطماطم","image_thumb":"\/images_large\/pasta.jpg","preferncess":["no salt"],"extrafield_1":"","extrafield_2":"","currency":"aed","description_russian":"","description":"pasta in napolitan sauce","preferncess_ids":["3"],"item_name_russian":"","currency_russian":"","note":"","item_id":"501","preferncess_arabic":["لا الملح"],"timestamp":"6\/23\/2014 9:47:45 pm","category":"pasta","price":["5"],"currency_arabic":"درهم","price":"18","item_name_arabic":"حساء الطماطم"},{"image_large":"\/images_large\/caeser-salad.jpg","promotion":"","food_type":"non","item_name":"caeser salad","unit":"20","id":"13","nutritional_info":"","description_arabic":"حساء الطماطم حساء الطماطم حساء الطماطم حساء الطماطمحساء الطماطم","image_thumb":"\/images_large\/caeser-salad.jpg","preferncess":["no salt","extra pepper"],"extrafield_1":"","extrafield_2":"","currency":"aed","description_russian":"","description":"a caesar salad salad of romaine lettuce , croutons dressed parmesan cheese.","preferncess_ids":["4","8"],"item_name_russian":"","currency_russian":"","note":"","item_id":"1001","preferncess_arab w/system.err(2122): @ org.json.json.typemismatch(json.java:111) w/system.err(2122): @ org.json.jsonobject.<init>(jsonobject.java:159) w/system.err(2122): @ org.json.jsonobject.<init>(jsonobject.java:172) w/system.err(2122): @ info.androidhive.jsonparsing.mainactivity$getcontacts.doinbackground(mainactivity.java:118) w/system.err(2122): @ info.androidhive.jsonparsing.mainactivity$getcontacts.doinbackground(mainactivity.java:1) w/system.err(2122): @ android.os.asynctask$2.call(asynctask.java:288) w/system.err(2122): @ java.util.concurrent.futuretask.run(futuretask.java:237) w/system.err(2122): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231) w/system.err(2122): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) w/system.err(2122): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) w/system.err(2122): @ java.lang.thread.run(thread.java:841)
first of data comes server in array form , try convert data json object.
now try below method:-
jsonarray obj = new jsonarray(jsonstr); jsonobject obj = jsonobj.getjsonobject(0); items = jsonobj.getjsonarray("items"); (int = 0; < items.length(); i++) { jsonobject c = items.getjsonobject(i); string id = c.getstring("id"); }
i think not getting item array that's why getting error.
Comments
Post a Comment