How to parse the JSON response in Blackberry/J2ME?

前端 未结 6 726
广开言路
广开言路 2020-12-01 16:46

I want to parse the response coming from the server in JSON format. I have done some googling but i can\'t find any library or jar kind of thing.

Everywhere there is

6条回答
  •  时光说笑
    2020-12-01 17:31

    I am developing a Blackberry client application and I confronted the same problem. I was searching for JSON way of parsing the response which I get from the server. I am using Eclipse plug-in for BB as IDE and it comes with BB SDK including the ones for JSON.

    The easiest answer to this question is that:

    Initially do not forget to use this import statement:

        import org.json.me.JSONObject;
    

    Then assign your JSON formatted response from the server to a String variable:

        String jsonStr = "{\"team\":\"Bursaspor\",\"manager\":\"Ertuğrul Sağlam\",\"year\":\"2010\"}";
    

    Create a JSONObject:

        JSONObject obj = new JSONObject(jsonStr);
    

    i.e. if you want to use the value of the "team" field which is "Bursaspor" then you should use your JSONObject like this:

        obj.getString("team")
    

    This call will return the string value which is "Bursaspor".

    P.S: I inspired this solution from this site which simply explains the solution of the same problem for Android development.

    http://trandroid.com/2010/05/17/android-ile-json-parse-etme-ornegi-1/

提交回复
热议问题