我从服务器获得了responseString,但是当我进入JSONObject时,出现了一个错误: JSONException
我的Json字符串在下面(我到底从服务器上得到了什么!)
[
{
"myregID": "APA91bHjhw8w_wo6eQOyhrtgx0w8Uypv-oxck28mRP3nfgmg0DFhRvfzpBNHncea7-YrxFV46-_8WVK2UQDXrk6_qqwtHnYlh63P-jobKfGaBi3khnGZ0q-mTLMmWc5ylnv1IcdVYFFRTQqK6oYjEz8BgP_JcxiJ9A",
"yourregID": "APA91bGuEcXeUwMl5PE74JB2KoVSsrYllQl4M0Pil6nPsTCBbMSngriODDLvpcDBgKY1sYj-4NiW8upgLb1VAPf2sgF5ZhUYg2Usdabg-s6CYRVJJBpDFX4MVvOUJ09pbb1lZsBuA6krXJ9CFSTdRBqyoPQid6zYKg"
}
]我的android客户端代码就在下面。
JSONObject jsonObject = new JSONObject(json);
tmp_myregID = jsonObject.getString("myregID");
Log.v("3333","1111");
tmp_yourregID = jsonObject.getString("yourregID");代码流在JSONObject jsonObject = new JSONObject(json)停止。
发布于 2014-10-26 07:36:04
首先需要获取数组[...],然后是对象{...}:
try {
JSONArray jsonArray = new JSONArray(jsonString);
JSONObject jsonObject = jsonArray.getJSONObject(0);
Log.e(TAG, jsonObject.getString("myregID"));
Log.e(TAG, jsonObject.getString("yourregID"));
} catch (JSONException e) {
e.printStackTrace();
}发布于 2014-10-26 07:34:38
您的Json根元素是一个JsonArray而不是Json对象,所以首先获取一个JsonArray。
https://stackoverflow.com/questions/26570790
复制相似问题