Json parsing in android is showing no results,Illegal Argument Exception,Host name may not be null -


this line of code giving me errors :

 httppost httppost = new httppost("file:///android_asset/www/me.json"); 

instead of file,even if use "http://xyz......"); still errors ./....................
import android.os.bundle; import android.app.activity; import android.webkit.webview; import android.widget.textview;

import java.io.bufferedreader; import java.io.inputstream; import java.io.inputstreamreader; import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.client.methods.httppost; import org.apache.http.impl.client.defaulthttpclient; import org.apache.http.params.basichttpparams;  public class mainactivity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);     textview tv=(textview)findviewbyid(r.id.tv1);     defaulthttpclient   httpclient = new defaulthttpclient(new basichttpparams());     httppost httppost = new httppost("file:///android_asset/www/me.json");      inputstream inputstream = null;      try {         httpresponse response = httpclient.execute(httppost);                    httpentity entity = response.getentity();         string result=null;         inputstream = entity.getcontent();         // json utf-8 default         bufferedreader reader = new bufferedreader(new inputstreamreader(inputstream,"utf-8"), 8);         stringbuilder sb = new stringbuilder();          string line = null;         while ((line = reader.readline()) != null)         {             sb.append(line + "\n");         }         result = sb.tostring();         tv.settext(result);     } catch (exception e) {         log.e("myapp", "exception", e);     }     {         try{if(inputstream != null)inputstream.close();}catch(exception squish){}     }     }  } 

and json file

{"resp": {"status": true, "version": "2.0", "artist": {"profile": "an australian rock band, formed in 1973 angus , malcolm young, teamed dave evans (vocals), larry van kriedt (bass) , colin burgess (drums). in 1974 both larry van kriedt , colin burgess left , replaced rob bailey (bass) , peter clack (drums), further change in 1974 saw peter clack leave , tony currenti (drums) join band. in june 1974 signed harry vanda & george young (malcolm & angus's brother) albert productions. in november 1974, dave evans left band , replaced bon scott (vocals & bagpipes). rob bailey left in 1974 , replaced george young (bass). in 1975 phil rudd (drums) replaced tony currenti , mark evans (bass) replaced george young.  in june 1977 mark evans left , replaced cliff williams (bass) first tour of usa. on 19 feb 1980 bon scott died @ age of 33. brian johnson (ex geordie) joined band replace him on vocals , album \"back in black\" released, tribute bon scott, album became 2nd largest selling album of time on 40 million copies sold worldwide. in may 1983, phil rudd had parting of ways , replaced simon wright (drums), aged 20 then. november 1989 simon wright left , replaced chris slade (ex manfred mann's earth band, uriah heep & firm). in summer 1994 phil rudd \"quietly\" rejoined band.\r\n\r\nac/dc australia's successful rock band ever, , popular around world.\r\nthe band inducted rock , roll hall of fame in 2003 performer.\r\n\r\ncurrent line-up:\r\nangus young (lead guitar)\r\nmalcolm young (rhythm guitar)\r\nbrian johnson (vocals)\r\ncliff williams (bass guitar)\r\nphil rudd (drums)\n", "releases_url": "http://api.discogs.com/artists/84752/releases", "name": "ac/dc", "uri": "http://www.discogs.com/artist/ac%2fdc", "members": ["angus young", "bon scott", "brian johnson", "chris slade", "cliff williams", "colin burgess", "dave evans", "larry van kriedt", "malcolm young", "mark evans (3)", "phil rudd", "simon wright (4)"], "urls": ["http://www.acdcrocks.com/", "http://www.acdc.com/", "http://www.acdcpower.net/", "http://www.myspace.com/acdc", "http://en.wikipedia.org/wiki/ac/dc"], "images": [{"uri": "http://api.discogs.com/image/a-84752-1233004620.jpeg", "height": 309, "width": 418, "resource_url": "http://api.discogs.com/image/a-84752-1233004620.jpeg", "type": "primary", "uri150": "http://api.discogs.com/image/a-150-84752-1233004620.jpeg"}, {"uri": "http://api.discogs.com/image/a-84752-1094915280.jpg", "height": 313, "width": 300, "resource_url": "http://api.discogs.com/image/a-84752-1094915280.jpg", "type": "secondary", "uri150": "http://api.discogs.com/image/a-150-84752-1094915280.jpg"}, {"uri": "http://api.discogs.com/image/a-84752-1105107816.jpg", "height": 129, "width": 180, "resource_url": "http://api.discogs.com/image/a-84752-1105107816.jpg", "type": "secondary", "uri150": "http://api.discogs.com/image/a-150-84752-1105107816.jpg"}, {"uri": "http://api.discogs.com/image/a-84752-1107645658.jpg", "height": 199, "width": 200, "resource_url": "http://api.discogs.com/image/a-84752-1107645658.jpg", "type": "secondary", "uri150": "http://api.discogs.com/image/a-150-84752-1107645658.jpg"}, {"uri": "http://api.discogs.com/image/a-84752-1182165014.jpeg", "height": 335, "width": 498, "resource_url": "http://api.discogs.com/image/a-84752-1182165014.jpeg", "type": "secondary", "uri150": "http://api.discogs.com/image/a-150-84752-1182165014.jpeg"}, {"uri": "http://api.discogs.com/image/a-84752-1233004627.jpeg", "height": 360, "width": 480, "resource_url": "http://api.discogs.com/image/a-84752-1233004627.jpeg", "type": "secondary", "uri150": "http://api.discogs.com/image/a-150-84752-1233004627.jpeg"}, {"uri": "http://api.discogs.com/image/a-84752-1233004633.jpeg", "height": 247, "width": 457, "resource_url": "http://api.discogs.com/image/a-84752-1233004633.jpeg", "type": "secondary", "uri150": "http://api.discogs.com/image/a-150-84752-1233004633.jpeg"}, {"uri": "http://api.discogs.com/image/a-84752-1233004641.jpeg", "height": 376, "width": 400, "resource_url": "http://api.discogs.com/image/a-84752-1233004641.jpeg", "type": "secondary", "uri150": "http://api.discogs.com/image/a-150-84752-1233004641.jpeg"}, {"uri": "http://api.discogs.com/image/a-84752-1233004648.jpeg", "height": 389, "width": 572, "resource_url": "http://api.discogs.com/image/a-84752-1233004648.jpeg", "type": "secondary", "uri150": "http://api.discogs.com/image/a-150-84752-1233004648.jpeg"}, {"uri": "http://api.discogs.com/image/a-84752-1297548279.jpeg", "height": 414, "width": 600, "resource_url": "http://api.discogs.com/image/a-84752-1297548279.jpeg", "type": "secondary", "uri150": "http://api.discogs.com/image/a-150-84752-1297548279.jpeg"}, {"uri": "http://api.discogs.com/image/a-84752-1294786426.jpeg", "height": 450, "width": 450, "resource_url": "http://api.discogs.com/image/a-84752-1294786426.jpeg", "type": "secondary", "uri150": "http://api.discogs.com/image/a-150-84752-1294786426.jpeg"}], "resource_url": "http://api.discogs.com/artists/84752", "id": 84752, "data_quality": "correct", "namevariations": ["ac / dc", "ac dc", "ac-dc", "ac//dc", "acdc", "dc/ac", "\u042d\u0439 \u0421\u0438 \u0414\u0438 \u0421\u0438"]}}} 

create jsonobject holds string parse each item jsonobject this:

myresponse =

{"resp": {"status": true, "version": ...

code :

jsonobject json_main = new jsonobject(myresponse); jsonobject c = json_main.getjsonobject("resp"); final string status= c.getstring("status"); 

example

how work this: {"resp": {"status": true, "version": "2.0"},"resp":{"status": true, "version": "3.0"}

   jsonobject json_main = new jsonobject(myresponse);        jsonarray main_arr = json_main.getjsonarray("resp");                                 for(int = 0; < main_arr.length(); i++)     {       jsonobject c = main_arr.getjsonobject(i);       final string status = c.getstring("status ");     } 

enter image description here


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -