我有WebAPI:http://some.com:39760/odata/DriverInfoes
当我点击链接时显示以下内容
{
"odata.metadata":"http://some.com:39760/odata/$metadata#DriverInfoes","value":[
{
"DriverID":"1","Name":"Faria","Phone":"ss","Email":"ss","Time":null
}
]
}
在android中我添加了odata4j-0.7.0-clientbundle来消费Odata
private class DownloadWebPageTask extends AsyncTask<Void, Void, OEntity> {
protected OEntity doInBackground(Void... params) {
String serviceUrl = "http://some.com:39760/odata/DriverInfoes ";
ODataConsumer consumer = ODataConsumers.create(serviceUrl);
return (OEntity) consumer.getEntities("DriverInfoes").execute(); //getting exception here
}
@Override
protected void onPostExecute(OEntity consumer) {
Log.v("mango", consumer.getType().getFullyQualifiedTypeName());
}
}
我在
上获得例外return (OEntity) consumer.getEntities("DriverInfoes").execute();
在我写的oncreate方法中
DownloadWebPageTask task = new DownloadWebPageTask();
task.execute();
但我没有运气。 我想我做错了什么! 任何人都可以指向我吗?
答案 0 :(得分:1)
其JSON数据...... 尝试使用JSONObject和JSONArray解析...
您的数据。
{
"odata.metadata": "http://some.com:39760/odata/$metadata#DriverInfoes",
"value": [
{
"DriverID": "1",
"Name": "Faria",
"Phone": "ss",
"Email": "ss",
"Time": null
}
]
}
使用以下代码解析您的数据......
JSONObject JObj=new JSONObject (jsonresult);
String metadata= JObj.getString("odata.metadata");
JSONArray array_list = JObj.getJSONArray("value");
//getting order Id from **order_list array**
for(int i=0;i<array_list.length();i++)
{
String DriverID= array_list.getJSONObject(i).getString("DriverID");
String Name= array_list.getJSONObject(i).getString("Name");
String Phone= array_list.getJSONObject(i).getString("Phone");
String Email= array_list.getJSONObject(i).getString("Email");
String Time= array_list.getJSONObject(i).getString("Time");
}