- Where Developers Learn, Share, & Build Careers
I have tried a lot but it is unable to parse JSN. I need all atrocities (book and camera) values in the array. Can anyone help me? How to arrange caremaOjects values and book object values. [{"Camera": {"picture": "http: \ / \ img7.flixcart.com \ image / -macyb5emj5yztet" camera ": {" picture ":" http: \ " "" "" "" "Model": "Lumix DMC-FP3 Point and Shoot", "Make": "Panasonic", "Price": 5830}}, {"Camera" "Sony" , "Price": 510}}, {/ sp.sony-europe.com} \ "/" "model": "digital still camera - h series - dcc-hx 200v", "make" "book": { "Description": "What is itself, and how can it be", "writers": "Douglas R. Hofstadter", "value": 650, "ID": 40724766, "title": "G \ u00f6del, asher, Bach : A Itanium Golden Brad "}}, {" Cam "": "{" Picture ":" http: \ / \ / www.usa.canon.com \ / 60d_586x186.gif "," model ":" digital SLR camera EOS 60D "," make ":" canyon ", "Price": 999}}, {"Book": {"Details": "TGDFGF FGFG", "Author": "Harold Ebelson and Gerald J. Suussman with Julie Sussman", "Value": 46 9, "Id ": 51087," Title ":" Structure and Analysis of Computer Programs "}},
I am using the code public is Zero GetDetalFromServer () {// Todo automatically generated method Stub
str Ng URL = "xyz.php"; HTTP Client Client = New DefaultHttpClient (); HTTP Post Post = New HTTP Post (URL); Try {HttpResponse response = client.execute (post); HttpEntity getResEntity = response.getEntity (); String result = ""; If (getResEntity! = Null) {Results = EntityUtils.toString (getResEntity); System.out.println ("Results from server:" + results); Bookdescription = New Arrestist & lt; String & gt; (); Book author = new arreelist & lt; String & gt; (); BookPrice = New Array's & lt; String & gt; (); BookID = new arreelist & lt; String & gt; (); BookTitle = New Arrestist & lt; String & gt; (); Feedback = New JSONArray (Results); (Int i = 0; i & lt; responseArray.length (); i ++) {JSONObject bookObject = (JSONObject) responseArray.getJSONObject (i); BookDescription.add (bookObject.get ("description") toString ().); BookAuthors.add (bookObject.get ("authors") toString ().); BookPrice.add (bookObject.get ("value") toString ().); bookID.add (bookObject.get ("id"). ToString ()); BookTitle.add (bookObject.get ("title"). ToString ());
}}} hold (exception e) {// TODO: handle exception}} Using this code, I just used the first object of the response I can get it. (Sanskar is now just trying to parse the music object, so why did not I take it) Thanks
< Pre> feedbackAre = new JSONArray (results); JSONObject bookObject = null; JSONObject json_user1 = Faucet; JSONObject json_user2 = Faucet; For (int i = 0; i & lt; responseArray.length (); i ++) {bookObject = responseArray.getJSONObject (i); If (bookObject.has ("book")) {json_user1 = bookObject.getJSONObject ("book"); BookDescription.add (json_user1.getString ("description") toString ().); BookAuthors.add (json_user1.getString ("authors") toString ().); } And if (bookObject.has ("camera")) {json_user2 = bookObject.getJSONObject ("camera"); / ** Add the camera data to the list which has been done for the book, please also see here. * />> Try it out ... inside your Jason array, you have Jason If you have inserted objects, you need to retrieve the book and the camera from the array such as the JSN objects and then you can get the details and all from the book object ...)
Comments
Post a Comment