请教:android转换json字符串
问题:在java工程中运行正常输出,在Android中运行总在net.sf.json.JSONArray jsonArr=net.sf.json.JSONArray.fromObject(jsonStr); 处出现异常:Unable to resolve superclass of Lnet/sf/json/JSONException; (1054)
以下是源代码
String jsonStr="[{Email:'a1',Password:'1122',UserName:'a1UserName'},{Email:'a2',Password:'33',UserName:'a2UserName'}]";
jsonStr="[{\"Email\":\"a1\",\"Password\":\"1122\",\"UserName\":\"a1UserName\"},{\"Email\":\"a2\",\"Password\":\"33\",\"UserName\":\"a2UserName\"}]";
net.sf.json.JSONArray jsonArr = net.sf.json.JSONArray
.fromObject(jsonStr);
System.out.println(jsonArr.size());
for (int i = 0; i < jsonArr.size(); i++) {
System.out.println("for");
net.sf.json.JSONObject jsonObj = jsonArr.getJSONObject(i);
HashMap<String, String> hMap = new HashMap<String, String>();
for (Iterator<?> iter = jsonObj.keys(); iter.hasNext();) {
String key = (String) iter.next();
System.out.println(key);
String value = jsonObj.get(key).toString();
System.out.println(value);
hMap.put(key, value);
}
}