如何在android中使用单个单词作为JSON数据?
我试图提取JSON数据,它只是一个单词。我曾经在JSON数组是一组数据的长列表时使用过它,但这次它只是一个类似-done或failed的单词 我的代码是-如何在android中使用单个单词作为JSON数据?,android,json,Android,Json,我试图提取JSON数据,它只是一个单词。我曾经在JSON数组是一组数据的长列表时使用过它,但这次它只是一个类似-done或failed的单词 我的代码是- JSONObject jsonObject = new JSONObject(s); //JSONArray jsonArray = jsonObject.getJSONArray("contacted"); loggingTest = jsonObject.getString("??"); // what to put here (??)
JSONObject jsonObject = new JSONObject(s);
//JSONArray jsonArray = jsonObject.getJSONArray("contacted");
loggingTest = jsonObject.getString("??"); // what to put here (??) as
//there is just a single word.
这可能很容易得到,但我觉得我错过了一些东西。提前谢谢你的帮助
URL只给出了一个类似于-done的词,这不是“甚至”或:{什么都没有
然后简单地使用字符串
变量s
,不要将其转换为json
另外,您可以将此JSONObject JSONObject=new JSONObject;
放在try catch
中,以识别respose是否只是一个有效的json,否则将引发异常
try{
// exception will be thrown in case of invalid json
JSONObject jsonObject = new JSONObject(s);
}
catch(JSONException e){
// s containing a single word so use it as it is
}
发布您想要从中提取的Json响应??URL只给出了一个类似于-done的单词,这不是“甚至”或:{nothing。