Monday, March 25, 2013

Parsing JSON object in Blackberry

Some time on sending http request server return JSON object so on blackberry side we need to write code that we can parse that object in display value on screen.

Following code is use full for parsing Json object in blackberry
To implement this code you need following lib on your project so plz download it from github.

https://github.com/upictec/org.json.me/

void parseJSONResponceInBB(String jsonStrFormat){  
     String[] readObject = {"Action"}; // Here my Json have "Action" Object to read you can change according your value.
        try {  
            JSONObject json = new JSONObject(jsonInStrFormat);  
            JSONObject jsonObj  = (JSONObject) json.get("result"); // You can change value according your return object.
            add(new LabelField(jsonObj.get(readObject[1])));
           
        } catch (JSONException e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }  
    }

Hope this code help full.

No comments:

Post a Comment