Json parsing using thread

JSON parsing using thread

Here, I have written a very simple method to parse JSON web service.

step 1
Show progress dialog before start thread.
Step 2
Create simple runnable Thread.
new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub                                   

Step 3
Parse JSON inside the Thread.

content="{"email":"" +"[email protected]"+  ""}";
        Log.d("Login content", content);
        try {
            json = jParser.getJSONFromUrl(new JSONObject(content),
                    url, "POST");
                    user_id = json.getString("user_id");
                data =(JSONObject)json.getJSONObject("error");
        } catch (JSONException e1) {
step 4
Handler for the current thread.
private final Handler handle_login = new Handler() {
public void handleMessage(Message msg) {
//Stop progress dialog here.
if(json !=null){
Toast.makeText(getApplicationContext(), "success", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "No Data", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Failed", Toast.LENGTH_SHORT).show();}}

Note: don’t forget to set INTERNET PERMISSION.

Leave a Reply

Your email address will not be published. Required fields are marked *