Overview:
Have always felt that this small thing Turing is a very fun thing, today went to the official website to look at, inside a piece of Java code Call sample, and is the main method encapsulated well, I think it can be used directly. No drama at all, in addition to their own import of a few bags, it has been perfectly run.
How to use:
Go to Turing's website: http://www.tuling123.com/openapi/
Register and get Apikey, and you'll be able to use the apikey where you plug in the code, even without adding any additional jar packages. Very convenient.
Java code shows:
public class Testtulingrobot {public static void main (string[] args) throws IOException {String sendinfo = "Nanjing Bus No. 45 "; String APIKEY = "Your API Key"; String INFO = Urlencoder.encode (Sendinfo, "utf-8"); System.out.println ("Send info:\n" + sendinfo); String GetURL = "http://www.tuling123.com/openapi/api?key=" + APIKEY + "&info=" + info; URL getUrl = new URL (getUrl); HttpURLConnection connection = (httpurlconnection) geturl.openconnection (); Connection.connect (); Get the input stream and use reader to read BufferedReader reader = new BufferedReader (New InputStreamReader (Connection.getinputstream (), "Utf-8")); StringBuffer sb = new StringBuffer (); String line = ""; while (line = Reader.readline ())! = null) {sb.append (line); } reader.close (); Disconnect Connection.disconnect (); System.out.println ("Receive info:\n" + SB); }}
The above code does not do any processing of the returned results, because the focus is not on the parsing of JSON, the relevant content can be self-access to the relevant information (of course, I think we are already familiar with the analysis of this data).
The accompanying source contains Java and a relatively complete Android code.
About the source code of Android, is to draw on the code of the cattle, no changes made, in this acknowledgment (this person's many blogs are good, worth learning):
http://blog.csdn.net/lmj623565791/article/details/38498353
Operating Effect:
Fig. 1
Fig. 2
Fig. 3
related source Download:
(Contains simple Java code and relatively complete Android code)
http://download.csdn.net/detail/u013761665/8743461
Turing man-java/android