Android JSON请求不提供任何内容

Android JSON请求不提供任何内容,android,json,Android,Json,我的代码中有一个bug,但我找不到它。我必须阅读下面JSON请求中的消息和代码 try { Log.d("qwertz", json); progressDialog.dismiss(); JSONObject jsonObject = new JSONObject(json); JSONArray jsonArray = jsonObject.getJSONArray("server_response"); JSONObject JO = jsonArr

我的代码中有一个bug,但我找不到它。我必须阅读下面JSON请求中的消息和代码

try {
    Log.d("qwertz", json);
    progressDialog.dismiss();
    JSONObject jsonObject = new JSONObject(json);
    JSONArray jsonArray = jsonObject.getJSONArray("server_response");
    JSONObject JO = jsonArray.getJSONObject(0);
    String code = JO.getString("code");
    String message = JO.getString("message");
    if (code.equals("win"))
    {
        showDialog("Du hast etwas gewonnen", message,code);
    }
    else if (code.equals("false"))
    {
        showDialog("Du hast leider nichts gewonnen", message,code);
    }

} catch (JSONException e) {
        e.printStackTrace();
}
这是一个JSON示例

{
    "server_response": {
        "code": "win",
        "message": "Du hast einen PzKpfw S35 739(f) gewonnen"
    }
}

我建议您不要自己直接处理json,相反,您可以使用许多库来完成这项工作。提到你可以使用或

如果仍要更正代码,可以尝试以下操作:

JSONObject response = jsonObject.getJsonObject("server_response");
String code = response.getString("code");

server\u response
不是数组。如何更改代码以读取代码或消息检查我的更新答案。非常感谢!我是瞎子:D