Android用汉字解析Json
我得到了一个有效的Json字符串(至少我尝试的每个onlinevalidator都这么说),其中包含一些中文字符 json字符串如下所示: {“标题”:“\u8981\u805e--\u83ef\u723e\u8857\u65e5\u5831”,“url”:”http://cn.wsj.com,“desc”:“\u300a\u83ef\u723e\u8857\u65e5\u5831\u300b\u4e2d\u6587\u7db2\u7d61\u7248\u6700\u65b0\u8ca1\u7d93\u8981\u805e”,“imageUrl”:null,“最新更新”:“1327588937”,“项”:[{“标题”:“\u4e16\u8cbf\u7d44\u7e54\u7e3d\u5e79\u4e8b\ufe55\u4eba\u6c11\u5e63\u5e63\u5e63\u503c\u8ab\u4f4e\u4f30\u4f40\u4f4e\u4f30\u7a0b\u5ea6\u4e0d\u660e”,“说明”:”\U4E6\U5E8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 u3002,“url”:http://cn.wsj.com/big5/20120126/BCHc-20120126WR182711424.asp?source=rss,“pubdate”:null}]} 现在,当我在Android中通过新的JsonObject(JsonString)解析JsonString时,我只得到了一些方块而不是字符 为什么android不能处理这个json字符串 任何帮助都将不胜感激 如果任何人想要服务器资源,可以在以下位置找到: //编辑Android用汉字解析Json,android,json,Android,Json,我得到了一个有效的Json字符串(至少我尝试的每个onlinevalidator都这么说),其中包含一些中文字符 json字符串如下所示: {“标题”:“\u8981\u805e--\u83ef\u723e\u8857\u65e5\u5831”,“url”:”http://cn.wsj.com,“desc”:“\u300a\u83ef\u723e\u8857\u65e5\u5831\u300b\u4e2d\u6587\u7db2\u7d61\u7248\u6700\u65b0\u8ca1\u7d
url已删除当您收到JSON时,您可能需要在生成结果时解码UTF-8结果。请查看utf8解码。类似于 然后是TextView.setText(testResult); 它对我有用 这是中国传统的弦乐要聞--華爾街日報"
可能您的ROM没有繁体中文字体???im已经在使用这个UTF-8参数:String json=EntityUtils.toString(responseEntity,HTTP.UTF_8);但是如果没有效果,则无法工作,这会在解析时给我一个JSONException(在:new JsonObject(result))如果您使用android SDK json解析器,您应该使用new org.json.JsonObject(String)也不起作用url编码后标题数据看起来是这样的:%E8%A6%81%E8%81%9E--%E8%8F%AF%E7%88%BE%E8%A1%97%E6%97%A5%E5%A0%b1我包含了可以访问json数据的url,但我已经编辑了我的答案。我的错误是,这与URLDecover.decode()或URLDecover.encode()无关。这是繁体中文字符串。可能是您的ROM没有繁体中文字体吗?我猜。您能用Emulator试试这段代码吗?
public static String test(){
String testResult= "";
try {
HttpGet get = new HttpGet("http://xxxxx");//edit url removed.
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(get);
String result = EntityUtils.toString(response.getEntity());
JSONObject obj = new JSONObject(result);
if(!obj.isNull("title")){
testResult= obj.getString("title");
Log.d("Test","Test1:"+ testResult);
}
} catch (JSONException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return testResult;//
}