能帮本人看看返回json的问题么?使用的百度APIStore的公交查询

移动开发 码拜 8年前 (2016-04-08) 911次浏览
API地址为:http://apistore.baidu.com/apiworks/servicedetail/790.html
想做一个调用相应这个api来实现微信查询公交信息的功能。
官方给出的java测试方法如下:
String httpUrl = “http://apis.baidu.com/apistore/bustransport/busstations”;
String httpArg = “city=%E5%8C%97%E4%BA%AC&station=%E4%BA%94%E9%81%93%E5%8F%A3”;
String jsonResult = request(httpUrl, httpArg);
System.out.println(jsonResult);
/**
* @param urlAll
*            :请求接口
* @param httpArg
*            :参数
* @return 返回结果
*/
public static String request(String httpUrl, String httpArg) {
BufferedReader reader = null;
String result = null;
StringBuffer sbf = new StringBuffer();
httpUrl = httpUrl + “?” + httpArg;
try {
URL url = new URL(httpUrl);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setRequestMethod(“GET”);
// 填入apikey到HTTP header
connection.setRequestProperty(“apikey”,  “您本人的apikey”);
connection.connect();
InputStream is = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(is, “UTF-8”));
String strRead = null;
while ((strRead = reader.readLine()) != null) {
sbf.append(strRead);
sbf.append(“\r\n”);
}
reader.close();
result = sbf.toString();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
里面apikey申请完了,测试执行以后能返回json了,但是内容是以下这样的:
{“errNum”:0,”retMsg”:”success”,”retData”:{“city”:”\u5317\u4eac”,”busNo”:”42″,”result”:”<?xml version=”1.0″ encoding=”utf-8″ ?>\n<root><result_num>16<\/result_num><web_url>http:\/\/apistore.baidu.com<\/web_url><wap_url>http:\/\/apistore.baidu.com<\/wap_url><lines><line><name>42\u7535\u8f66(\u4e1c\u56db\u5341\u6761\u6865-\u5e7f\u5916\u7518\u77f3\u6865)<\/name><info>\u4e1c\u56db\u5341\u6761\u68655:30-23:00|\u5e7f\u5916\u7518\u77f3\u68655:30-23:00
本人看代码里面有相应utf-8的处理啊。
是需要再处理一下么?能帮忙给看下么?
解决方案

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明能帮本人看看返回json的问题么?使用的百度APIStore的公交查询
喜欢 (0)
[1034331897@qq.com]
分享 (0)