How to create json file.

Total Post:6


 1599  View(s)
Rate this:
Anyone can give me an idea about json file with server, like getting a file text? or how to create a .json file so i can put it in asset folder as my text file.
  1. Re: How to create json file.

    Use below code for get json from any server

    class MyAsyncTask extends AsyncTask<String, String, Void> {
    private ProgressDialog progressDialog = new ProgressDialog(context);
    InputStream inputStream = null;
    String result = "";
    protected void onPreExecute() {
    progressDialog.setMessage("Please wait downloading your data...");;
    progressDialog.setOnCancelListener(new OnCancelListener() {
    public void onCancel(DialogInterface arg0) {
    protected Void doInBackground(String... params) {
    // set your url of json file
    String url_select = "";
    ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();
    try {
    // Set up HTTP post
    // HttpClient is more then less deprecated. Need to change to
    // URLConnection
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url_select);
    httpPost.setEntity(new UrlEncodedFormEntity(param));
    HttpResponse httpResponse = httpClient.execute(httpPost);
    HttpEntity httpEntity = httpResponse.getEntity();
    // Read content & Log
    inputStream = httpEntity.getContent();
    } catch (Exception e4) {
    // Convert response to string using String Builder
    try {
    BufferedReader bReader = new BufferedReader(
    new InputStreamReader(inputStream, "utf-8"), 8);
    StringBuilder sBuilder = new StringBuilder();
    String line = null;
    while ((line = bReader.readLine()) != null) {
    sBuilder.append(line + "\n");
    result = sBuilder.toString();
    } catch (Exception e) {
    return null;
    } // protected Void doInBackground(S
    protected void onPostExecute(Void v) {
    // parse JSON data
    try {
    JSONArray jArray = new JSONArray(result);
    for (int i = 0; i < jArray.length(); i++) {
    JSONObject jObject = jArray.getJSONObject(i);
    String name = jObject.getString("name");
    String tab1_text = jObject.getString("tab1_text");
    int active = jObject.getInt("active");
    } // End Loop
     catch (Exception e)
    } // protected void onPostExecute(Void v)
    } // class MyAsync

      Modified On Apr-10-2018 12:34:32 AM
  1. Re: How to create json file.

    how can i call that? sorry noob here

  1. Re: How to create json file.

    new MyAsyncTask() .execute();

      Modified On Jun-22-2015 04:16:33 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.