我想要做的是得到一個響應,但不知道如何從中提取值。解析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);
你是說你需要提取一些關鍵'urdu'的值?我問,因爲根據你發佈的JSON,這是不可能的(因爲在任何地方都沒有'urdu')。 – Mike
不,我想提取[「کراچی」]這個值...我問的是關於烏爾都語文本 – user1162546
什麼是期望的輸出? – Vedda