ImportCom.alibaba.fastjson.JSONArray;ImportCom.alibaba.fastjson.JSONObject;ImportJava.io.BufferedReader;ImportJava.io.InputStream;ImportJava.io.InputStreamReader;Importjava.net.MalformedURLException;ImportJava.net.URL; Public StaticString calcmobilecity (String mobilenumber)throwsmalformedurlexception{String jsonstring=NULL; Jsonarray Array=NULL; Jsonobject Jsonobject=NULL; //get the API address of the PAT netString urlstring = "http://virtual.paipai.com/extinfo/GetMobileProductInfo?mobile=" +mobilenumber+ "&amount= 10000&callname=getphonenuminfoextcallback "; StringBuffer SB=NewStringBuffer (); BufferedReader buffer; URL URL=NewURL (urlstring); Try{//get the page content in the URL addressInputStream in =Url.openstream (); //Solve garbled problemsBuffer =NewBufferedReader (NewInputStreamReader (In, "gb2312")); String Line=NULL; //read data in one row while(line = Buffer.readline ())! =NULL) {sb.append (line); } in.close (); Buffer.close (); //System.out.println (sb.tostring ()); Jsonstring =sb.tostring (); //Replace the "Getphonenuminfoextcallback (,);<!--[if!] ie]>|xgv00|6741027ad78d9b06f5642b25ebcb1536<! [endif]--> ", so that it can be converted to a Jsonarray objectjsonstring = Jsonstring.replace ("Getphonenuminfoextcallback (", "["); Jsonstring= Jsonstring.replace (");<!--[if! ie]>|xgv00|6741027ad78d9b06f5642b25ebcb1536<! [endif]--> ","] "); //Convert jsonstring to JSON object//array = jsonarray.fromobject (jsonstring); Array =Jsonarray.parsearray (jsonstring); //gets the Jsonobject object of the Jsonarray, making it easy to read the key value pairs in the arrayJsonobject = Array.getjsonobject (0); }Catch(Exception e) {e.printstacktrace (); }//reads the city name from the Jsonobject object returnJsonobject.getstring ("CityName"); }
Get a place of attribution based on your mobile phone number