android - How to parse json data -


I'm very new to getting JSON data from the web, so I'm a bit confused here how to get this JSON data in Android Do: I'm getting an error in Jasonoon.

Like it in the log cat.

  02-16 21: 31: 25.093: W / System System. Er (22428): org.json.JSONException: value {"3": {"ID": 1172, "title": "dsfsdf"}, "9": {"id": 1172, "title": "dsfsdf "": "8": {"id": 1172, "title": "dsfsdf"}, "7": {"id": 1172, "title": "dsfsdf"}, "6": {"id "": 1172, "title": "dsfsdf"}, "5": {"id": 1172, "title": "dsfsdf"}, "4": {"id": 1172, "title": "dsfsdf "}} Type of data can not be translated into org.json.JSONObject JSONArray 02-16 21: 31: 25.133: W / Systems. Er (22428): at org.json.JSON.typeMismatch (JSON.java: 100) 02-16 21: 31: 25.138: W / Systems. Er (22428): at org.json.JSONObject.getJSONArray (JSONObject.java-- 48) 02-16 21: 31: 25.138: W / Systems. Er (22428): $ MyPickAsyncTask.doInBackground on auto.life.dashboard.LeftSideMenuController (LeftSideMenuController.java:1807) 02-16 21: 31: 25.138: W / Sistm.aarar (22428): auto.life.dashboard.LeftSideMenuController $ MyPickAsyncTask.doInBackground (LeftSideMenuController.java:1) on 02-16 21: 31: 25.138: W / Sy Stem. ARR (22428): Android.OS Async Task $ 2.Coll (Async Task.Java 287) 02-16 21: 31: 25.138: W / Systems. Er (22428): Sync.innerRun (futureTask.java.305) at java.util.concurrent.futureTask $ 02-16 21: 31: 25.138: W / Systems. Er (22428): at java.util.concurrent.FutureTask.run (FutureTask.java:137) 02-16 21: 31: 25.138: W / Systems. ARR (22428): Android.Oce Async Task $ Serial Expector $ 1.R (Async Task Java 3030) 02-16 21: 31: 25.138: W / Systems. Er (22428): but Java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1076) 02-16 21: 31: 25.138: W / Systems. Er (22428): at java.util.concurrent.ThreadPool Excluer $ Worker.run (ThreadPoolExecutor.java: 56 9) 02-16 21: 31: 25.138: W / Systems. Get er (22428) on JavaklangkThreadkrun (Thredkjawa: 856) 02-16 21: 36: 26.873: W / IInputConnectionWrapper (22428)): Select receive input output connections 02-16 21: 36: 26.873: W / IInputConnectionWrapper (22428): passive input connection on Krensncharkod 02-16 21: 36: 26.873: W / IInputConnectionWrapper (22428): inactive Inpu getExtractedText Tiknekshn   to 

I Here is the Jason data like this. "" ":" ":" ":" "": "" ":" "": "" ":" "": "" ":" "": "Title": "dsfsdf"}, "4": {"ID": 1172, "title": "dsfsdf"}, "5": {"ID": 1172, "title": "7": {" Id ": 1172," title ":" dsfsdf "}," 8 ": {" id ":" 11 "," title ":" id ":" title ":" dsfsdf "} {" id ": 1172, "Title": "dsfsdf"}, "9": {"id": 1172, "title": "dsfsdf"}}}

To get data from Java: < / p>

  list & lt; nameValuePair & gt; MypickDetails = new ArrayList & lt; NameValuePair & gt; (); MypickDetails.add (new BasicNameValuePair ( "_ event", event)); MypickDetails.add (New BasicNameValuePair ("user_id", userID)); HTT Client HC = new default Olt HTTP client (); Actiteepeepost HP = new HTTP Post (Acteepeepithkurl); {Hp.setEntity (Try new UrlEncodedFormEntity (mypickDetails)); // Execute HTTP POST request HttpResponse response = Hckexecute (HP): String Result = EntityUtils.toString (response.getEntity ()); string jsontext = new string (result); // JSONObject entries = according to the new JSONObject (jsontext) the object according to the Jason format result; JSONArray postListArray = Entries .getJSONArray ("Data"); For (int i = 0; i & lt; postListArray.length (); i ++) {log d. ("Get value", "+ ----" + post listar.lamp ()); JSONObject postListObj = postListArray.getJSONObject (i); String myPickName = postListObj.getString ("title"); DashboardVariables.mypickname.add (myPickName); }   

Thank you in advance.

  "data": {  

Data is not a a JSONArray . It has a JSONObject .

But you have

  JSONArray postListArray = entries .getJSONArray ("data"); // false   

{ represents a Jason object node

[ a Jason array node represents

  "data": {// json object data "3": {// json object 3 "id": 1172, // int "title": "dsfsdf" / / string}   

use

  JSONObject jb = (JSONObject) entries .getJSONObject ( "data"); JSONObject three = jb.getJSONObject ("3"); Int id = three.getInt ("ID"); String title = three .getString ("title");    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -