Question
JSON Data Fetching And Parsing From URL with Android Studio problem. Please help I'm trying to parse the following JSON file but am not able
"JSON Data Fetching And Parsing From URL" with Android Studio problem. Please help I'm trying to parse the following JSON file but am not able to do so: api.myjson.com/bins/ z5x5e Is there anything wrong with my code?
Source Code:
AndroidManifest.xml
fetchData.java
package com.abhishekpanwar.receivedatajson;
import android.os.AsyncTask;
import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject;
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL;
public class fetchData extends AsyncTask
JSONArray JA = new JSONArray(data); for(int i =0 ;i < JA.length(); i++){ JSONObject JO = (JSONObject) JA.get(i); singleParsed = "Type:" + JO.get("type") + "Title:" + JO.get("title") + "Venue:" + JO.get("venue") + "Location:" + JO.get("location") + "Time:" + JO.get("time") + "Description:" + JO.get("desc") + "More:" + JO.get("more");
dataParsed = dataParsed + singleParsed;
}
} catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); }
return null; }
@Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid);
MainActivity.data.setText(this.dataParsed);
} }
MainActivity.java
package com.abhishekpanwar.receivedatajson; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity { Button click; public static TextView data; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); click = (Button) findViewById(R.id.button); data = (TextView) findViewById(R.id.fetcheddata); click.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { fetchData process = new fetchData(); process.execute(); } }); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started