我的应用程序从链接获取JSON数据,但我需要从JSON获取状态。
以下是我的工作:
截图:
我需要输出>
任何帮助都会很好或指向我的方向,谢谢。
我的一些代码:
public class doit extends AsyncTask<Void,Void,Void>{
String words;
public doit() throws JSONException {
}
@Override
protected Void doInBackground(Void... voids) {
try {
WebView wv = (WebView) findViewById(R.id.webview);
EditText messages = (EditText) findViewById(R.id.messages);
Document doc = Jsoup.connect("https://api.deepbot.tv/web/apply/namerefresh.php?s=" + messages.getText().toString()).get();
words=doc.text();
}catch(Exception e){e.printStackTrace();}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
texx.setText(words);
}
答案 0 :(得分:0)
尝试以下操作,只需替换您的退货:
public class doit extends AsyncTask<Void,Void,Void>{
String words;
public doit() throws JSONException {
}
@Override
protected Void doInBackground(Void... voids) {
try {
WebView wv = (WebView) findViewById(R.id.webview);
EditText messages = (EditText) findViewById(R.id.messages);
Document doc = Jsoup.connect("https://api.deepbot.tv/web/apply/namerefresh.php?s=" + messages.getText().toString()).get();
words=doc.text();
}catch(Exception e){e.printStackTrace();}
return words;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
try {
JSONObject jObj = new JSONObject(words);
String code = jObj.getString("code");
String name = jObj.getString("msg");
texx.setText(code +" "+name);
} catch (JSONException e) {
e.printStackTrace();
}
}
答案 1 :(得分:0)
Checkout awesome library Gson 你只需要为响应创建Object,你就会得到它
Response response = gson.fromJson("words", Response.class);
响应包含您的所有需求。
或强>
您可以使用json parser tutorials。
答案 2 :(得分:0)
块引用
JSONObject jObj = arr.getJSONObject(words);
String date = jObj.getString("msg");
块引用
答案 3 :(得分:0)
1。首先创建一个带有响应字符串JSONObject
的{{1}}。
words
2. 从您的回复JSONObject JSONObject jsonObject = new JSONObject(words);
获取JSONObject status
:
words
3。最后,从 JSONObject jsonObjectStatus = jsonObject.getJSONObject("status");
JSONObject解析code
和msg
字符串,如下所示:
status
更新 String code = jsonObjectStatus.getString("code");
String msg = jsonObjectStatus.getString("msg");
,如下所示:
onPostExecute()