我试图将json对象解析为我的andorid应用程序,但它给了我这个例外..
5-02 22:16:34.711 1420-1437/com.tutecentral.restfulapiclient D/JSONParser => parseDepartment﹕ No value for Value
05-02 22:16:34.711 1420-1437/com.tutecentral.restfulapiclient W/System.err﹕ org.json.JSONException: No value for Value
05-02 22:16:34.735 1420-1437/com.tutecentral.restfulapiclient W/System.err﹕ at org.json.JSONObject.get(JSONObject.java:354)
05-02 22:16:34.735 1420-1437/com.tutecentral.restfulapiclient W/System.err﹕ at org.json.JSONObject.getJSONArray(JSONObject.java:544)
05-02 22:16:34.739 1420-1437/com.tutecentral.restfulapiclient W/System.err﹕ at com.tutecentral.restfulapiclient.JSONParser.parseDepartment(JSONParser.java:22)
05-02 22:16:34.739 1420-1437/com.tutecentral.restfulapiclient W/System.err﹕ at com.tutecentral.restfulapiclient.DeptActivity$AsyncLoadDeptDetails.doInBackground(DeptActivity.java:64)
05-02 22:16:34.739 1420-1437/com.tutecentral.restfulapiclient W/System.err﹕ at com.tutecentral.restfulapiclient.DeptActivity$AsyncLoadDeptDetails.doInBackground(DeptActivity.java:48)
05-02 22:16:34.739 1420-1437/com.tutecentral.restfulapiclient W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:287)
我的json
{
"name": "JSONWebAPI",
"description": "JSON API for android appliation",
"url": "http://HAMAD/New_ExampleWEB/handler1.ashx",
"interfaces": [
{
"name": "Service1",
"methods": [
{
"name": "CreateNewAccount",
"parameters": [
{
"name": "firstName",
"type": "string"
},
{
"name": "lastName",
"type": "string"
},
{
"name": "userName",
"type": "string"
},
{
"name": "password",
"type": "string"
}
],
"returnvalue": "void"
},
{
"name": "GetUserDetails",
"parameters": [
{
"name": "userName",
"type": "string"
}
],
"returnvalue": "object"
},
{
"name": "UserAuthentication",
"parameters": [
{
"name": "userName",
"type": "string"
},
{
"name": "passsword",
"type": "string"
}
],
"returnvalue": "boolean"
},
{
"name": "GetDepartmentDetails",
"parameters": [],
"returnvalue": "object"
}
]
}
]
}
这是我的代码
public ArrayList<DeptTable> parseDepartment(JSONObject object)
{
ArrayList<DeptTable> arrayList=new ArrayList<DeptTable>();
try {
JSONArray jsonArray=object.getJSONArray("Value");
JSONObject jsonObj=null;
for(int i=0;i<jsonArray.length();i++)
{
jsonObj=jsonArray.getJSONObject(i);
arrayList.add(new DeptTable(jsonObj.getInt("no"), jsonObj.getString("name")));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
Log.d("JSONParser => parseDepartment", e.getMessage());
e.printStackTrace();
}
return arrayList;
}
我正在使用本教程
答案 0 :(得分:0)
getJSONArray(&#34; Value&#34;)将获得跟随它的数组,如下所示:
"Value" : [ "test1", "test2" ]
您的JSON中没有以&#34;值&#34;为前缀的数组。因此它失败了。有点难以确定&#34;价值&#34;应该没有更多细节。