Alirezaaraby :
I Have A Project And In That Project, I Should Parse Two JSON Together.
I Should Get Url From First JSON Using com.squareup.okhttp3:okhttp:4.4.0
And First JSON Is Looks Like:
{
"Url": {
"Url":"https://example.com/Myjson.json"
}
}
And I Want to Get The "Url" Key From First JSON And Put That Url For Second JSON Url And Second One Is Looks Like:
{
"Head":
{
"Version" : "",
"WebSite" : "",
"Instagram" : "",
"Telegram" : "",
},
"Banner" :
{
"Banner_Tittle":"",
"Banner_Description":""
},
"Version_Banner":
{
"Version_Banner_Tittle" : "",
"Version_Banner_Description" : "",
"Version_Banner_Link" : ""
},
"News": [
{
"Tittle" : "",
"Description" : "",
"Image" : "",
}
],
"Class": [
{
"Tittle" : "",
"Description" : "",
"Image" : "",
}
]
}
And My JSON Parser Class Is Below:
private class GetVersion extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(final Void... arg0) {
JSONObject JsonMain = null;
HttpHandler Handler = new HttpHandler();
String jsonStr = Handler.makeServiceCall("MyFirstJSONURL");
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
JsonMain = jsonObj.getJSONObject("Url");
URL_2 = JsonMain.getString("Url");
}
}
}
}
And Now I Want TO Know How To Do That With Android Studio
A_Singh7 :
Declare two classes which extend AsyncTask(one of which you have already declared).
After that, in the onPostExecute method of the first one(GetVersion), execute the second class which takes the URL string and opens a connection to retrieve the JSON file and parse it there.
Something like :-
private class GetLocation......
{
@Override
protected void onPostCreate (Void v)
{
//Execute second class here
}
}
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=366602&siteId=1