我有以下格式的JSON内:如何解析JSON字符串是一个数组
{ "Result": { "question": "Barack Obama vs Mitt Romney?", "option": [ "Barack Obama", "Mitt Romney", "Other" ], "percentage": [ 20, 40, 80 ] } }
,我使用下面的代码来分析它,但在选择阵列此给空指针异常。
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONObjectFromUrl(url);
Log.e("json",json.toString());
Log.e("-------url-------", ""+url);
String resultStr = json.getString("Result");
Log.e("result string ",resultStr);
JSONObject jsonObject2 = new JSONObject(resultStr);
String question_string = jsonObject2.getString("question");
Log.e("question String ",question_string);
String option_str = jsonObject2.getString("option");
JSONArray optionArray = new JSONArray(option_str);
Log.d("option array", String.valueOf(optionArray.length()));
这里是你的家庭作业:Android的 - JSON解析示例](HTTP ://stackoverflow.com/search?q = Android + json +解析+例子) – 2013-05-13 06:56:53