在java中解析JSON响应以提取值
我想做的是得到一个响应,但不知道如何从中提取值
实际反应如下:
[
"SUCCESS",
[ [
"Karachi",
["کراچی"],
[],
{
"candidate_type": [0],
"is_confident": [true]
}
]]
]
我需要从中提取urdu
文本
String text = "Karachi";
String url = "https://inputtools.google.com/request";
try {
final HttpClient client = new HttpClient();
final PostMethod method = new PostMethod(url);
method.setParameter("text", text);
method.setParameter("itc", "ur-t-i0-und");
method.setParameter("num", "1");
method.setParameter("cp", "0");
method.setParameter("cs", "1");
method.setParameter("ie", "utf-8");
client.executeMethod(method);
BufferedReader strResponse = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(),"UTF-8"));
Object jObj = (Object) JSON.parse(strResponse);
# 1 楼答案
我创建了一个适用于所有JSON的包装器:
# 2 楼答案
试试这个(你的缓冲区读卡器可能不止一行):