1 ) Demo Dao
Response
2 ) Demo Dao
"permissions": {
"CREATE_SITE": "true"
},
"MainJsonObject": {
"ALL": "true",
"articleList": [
{
"title": "One",
"url": "http://hmkcode.com/android-internet-connection-using-http-get-httpclient/",
"categories": [
"Android"
],
"tags": [
"android",
"httpclient",
"internet"
]
},
{
"title": " Two",
"url": "http://hmkcode.com/android-camera-taking-photos-camera/",
"categories": [
"Android"
],
"tags": [
"android",
"camera"
]
},
{
"title": " Three",
"url": "http://hmkcode.com/android-camera-taking-photos-camera/",
"categories": [
"Android"
],
"tags": [
"android",
"camera"
]
},
{
"title": " Four ",
"url": "http://hmkcode.com/android-camera-taking-photos-camera/",
"categories": [
"Android"
],
"tags": [
"android",
"camera"
]
},
{
"title": " Five ",
"url": "http://hmkcode.com/android-camera-taking-photos-camera/",
"categories": [
"Android"
],
"tags": [
"android",
"camera"
]
}
]
}
}
package com.example.discusit.demoblogapitest.dao; import android.content.Context; import android.util.Log; import com.example.discusit.demoblogapitest.model.DemoModel; import com.example.discusit.demoblogapitest.webservices.WebFields; import org.json.JSONArray; import org.json.JSONObject; import java.util.ArrayList; public class DemoDao implements OnDemoAPITestListener { private Context mActivity; private String status,message,data,id, name,country,city,mobile,android; public DemoDao(Context context) { this.mActivity=context; } @Override public ArrayList<DemoModel> getDemoData(Context context, JSONObject jsonObject) { ArrayList<DemoModel> mArrDemoData = new ArrayList<DemoModel>(); try { // for(int i=0; i<jsonObject.length(); i++)// { status=jsonObject.getString(WebFields.TESTAPI.RESPONSE_STATUS); message=jsonObject.getString(WebFields.TESTAPI.RESPONSE_MESSAGE); data=jsonObject.getString(WebFields.TESTAPI.RESPONSE_ARR_DATA); JSONArray jsonArray1 = new JSONArray(data); for(int j=0;j<jsonArray1.length();j++) { JSONObject jsonDoc = jsonArray1.getJSONObject(j); id = jsonDoc.getString(WebFields.TESTAPI.RESPONSE_ID); name = jsonDoc.getString(WebFields.TESTAPI.RESPONSE_NAME); country = jsonDoc.getString(WebFields.TESTAPI.RESPONSE_COUNTRY); city = jsonDoc.getString(WebFields.TESTAPI.RESPONSE_CITY); mobile=jsonDoc.getString(WebFields.TESTAPI.RESPONSE_ARR_MOBILE); JSONArray jsonArrayMobile = new JSONArray(mobile); Log.e("Length:>>>>>>>>>>", String.valueOf(jsonArrayMobile.length())); for (int m=0;m<jsonArrayMobile.length();m++) { JSONObject jsonAndroid = jsonArrayMobile.getJSONObject(m); android=jsonAndroid.getString(WebFields.TESTAPI.RESPONSE_ANDROID); DemoModel demoModel = new DemoModel(status,message,id,name,country,city,android); mArrDemoData.add(demoModel); } } Log.e("Size:>>>>>>>>>>", String.valueOf(mArrDemoData.size())); // } } catch (Exception exception) { Log.e("ERROR:>>>>>>>>>>", String.valueOf(exception)); } return mArrDemoData; } }
Response
--------------------------------------------------------------------------------------------------------------------------
{
"status": "true",
"message": "Data fetched successfully!",
"data": [
{
"id": "1",
"name": "Roger Federer",
"country": "Switzerland",
"city": "Basel",
"mobile": [
{
"android": "Samsung"
}
]
},
{
"id": "2",
"name": "Rafael Nadal",
"country": "Spain",
"city": "Madrid",
"mobile": [
{
"android": "One PLus"
}
]
},
{
"id": "3",
"name": "Novak Djokovic",
"country": "Serbia",
"city": "Monaco",
"mobile": [
{
"android": "Redmi"
}
]
},
{
"id": "4",
"name": "Andy Murray",
"country": "United Kingdom",
"city": "London",
"mobile": [
{
"android": "Gionee"
}
]
},
{
"id": "5",
"name": "Maria Sharapova",
"country": "Russia",
"city": "Moscow",
"mobile": [
{
"android": "RealMe"
}
]
},
{
"id": "6",
"name": "Caroline Wozniacki",
"country": "Denmark",
"city": "Odense",
"mobile": [
{
"android": "Oppo"
}
]
},
{
"id": "7",
"name": "Eugenie Bouchard",
"country": "Canada",
"city": " Montreal",
"mobile": [
{
"android": "Vivo"
}
]
},
{
"id": "8",
"name": "Ana Ivanovic",
"country": "Serbia",
"city": "Belgrade",
"mobile": [
{
"android": "Nokia"
}
]
}
]
}
2 ) Demo Dao
import android.content.Context; import android.util.Log; import com.example.discusit.sqlitedatabasedemowithapicalling.model.DemoModel; import com.example.discusit.sqlitedatabasedemowithapicalling.webservices.WebFields; import org.json.JSONArray; import org.json.JSONObject; import java.util.ArrayList; public class DemoDao implements OnDemoListener { private String All; private String Title; private String Url; private ArrayList<String>mArrayCategory; private String mainObject; private String articleList; private String category; private Context mActivity; public DemoDao(Context context) { this.mActivity=context; } @Override public ArrayList<DemoModel> getDemoList(Context context, JSONObject jsonObject) { ArrayList<DemoModel> mDemoListModel = new ArrayList<DemoModel>(); try { mainObject=jsonObject.getString(WebFields.Main_OBJECT_LIST.RESPONSE_MAIN_JSON_OBJECT); JSONObject jsonObjectMain=new JSONObject(mainObject); All=jsonObjectMain.getString(WebFields.Main_OBJECT_LIST.RESPONSE_ALL); articleList=jsonObjectMain.getString(WebFields.Main_OBJECT_LIST.RESPONSE_ARR_MAIN_ARTICLE_LIST); JSONArray jsonArrayArticleList=new JSONArray(articleList); Log.e("Size:>>>>>>>>>>>", String.valueOf(jsonArrayArticleList.length())); for(int i=0; i<jsonArrayArticleList.length(); i++) { JSONObject jsonObject1 = jsonArrayArticleList.getJSONObject(i); // JSONArray jsonArray1=jsonObject1.getJSONArray(WebFields.Main_OBJECT_LIST.RESPONSE_ARR_CATEGORIES); Title= jsonObject1.getString(WebFields.Main_OBJECT_LIST.RESPONSE_TITLE); Url = jsonObject1.getString(WebFields.Main_OBJECT_LIST.RESPONSE_URL); // mArrayCategory.add(jsonArray1.get(i).toString()); DemoModel demoModel = new DemoModel(All,Title,Url,mArrayCategory); mDemoListModel.add(demoModel); } } catch (Exception exception) { Log.e("Error:>>>>>>>>>>>", String.valueOf(exception)); } return mDemoListModel; } }
Response
--------------------------------------------------------------------------------------------------------------------------
"CREATE_SITE": "true"
},
"MainJsonObject": {
"ALL": "true",
"articleList": [
{
"title": "One",
"url": "http://hmkcode.com/android-internet-connection-using-http-get-httpclient/",
"categories": [
"Android"
],
"tags": [
"android",
"httpclient",
"internet"
]
},
{
"title": " Two",
"url": "http://hmkcode.com/android-camera-taking-photos-camera/",
"categories": [
"Android"
],
"tags": [
"android",
"camera"
]
},
{
"title": " Three",
"url": "http://hmkcode.com/android-camera-taking-photos-camera/",
"categories": [
"Android"
],
"tags": [
"android",
"camera"
]
},
{
"title": " Four ",
"url": "http://hmkcode.com/android-camera-taking-photos-camera/",
"categories": [
"Android"
],
"tags": [
"android",
"camera"
]
},
{
"title": " Five ",
"url": "http://hmkcode.com/android-camera-taking-photos-camera/",
"categories": [
"Android"
],
"tags": [
"android",
"camera"
]
}
]
}
}
Comments
Post a Comment