What happens if you use:

JSONObject object = new JSONObject(json);

and omit the tokenizer.


--- On Mon, 10/31/11, Ashish Tiwari <[email protected]> wrote:

From: Ashish Tiwari <[email protected]>
Subject: [android-developers] Parsing JSON data using JSONTokener shows nothing 
...
To: [email protected]
Received: Monday, October 31, 2011, 11:38 AM


package com.json.main;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class JSONtestActivity extends Activity {     /** Called when the 
activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.main);
           //TextView tv1 = (TextView)findViewById(R.id.TextView01);
           //tv.setText("Hey see this,its working..");
        
        
         try {
                        
                  /* Inflate TextView from the layout */
                        
                  TextView tv = (TextView)findViewById(R.id.TextView01);
                        
                 /* JSON data considered as an example. Generally this data is 
obtained
                 from a web service.*/
                        
                  String json = "{"+
                                           " \"name\" :\"ashish\", " +
                                          " \"message\" :\"hey see this,it 
works\", " +
                                           " \"place\" :\"vileparle\", " +
                                           " \"date\" :\"Todays date will goes 
here  \", " +
                                 "  }"; 
                        
                 JSONObject object = (JSONObject) new 
JSONTokener(json).nextValue();
                   String name = object.getString("name");
                 String message = object.getString("message");
                   String place = object.getString("place");
                 String date = object.getString("date");
                        
                  tv.setText("Name : " + name + "\n \n");
                  tv.setText("Message" + message + "\n \n");
                  tv.setText("Place" + place + "\n \n ");
                   tv.setText("Data" + date + "\n \n"); 
                        
         } catch (JSONException e) {
                    e.printStackTrace();
         }
          catch(Exception ex){
                 ex.printStackTrace();
                  }
         }
}

/*
here is XML >
 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">        
 
 
    <TextView
        android:id="@+id/TextView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="No data"/>
 
</LinearLayout>
 
*/


It shows " No data ". here is pastebin's link >http://pastebin.com/xw2TPd2U




-- 

You received this message because you are subscribed to the Google

Groups "Android Developers" group.

To post to this group, send email to [email protected]

To unsubscribe from this group, send email to

[email protected]

For more options, visit this group at

http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to