Get a place of attribution based on your mobile phone number

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.