0

I make connection with my webservices (SOAP) this the xml result that I recieved from the webservices how can I parse this result,

<string>{"30_year_rate":4.250,"30_year_pi":196.78,"30_year_apr":4.375,"QuoteID":1434,"Licensed":"N"}</string>

can anybody tell me how?

Many thanks!

Vishnu
  • 349
  • 3
  • 8
  • 16

2 Answers2

1

Use Below Code Snippet

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    String readTwitterFeed = readTwitterFeed();
    try {
        JSONArray jsonArray = new JSONArray(readTwitterFeed);
        Log.i(ParseJSON.class.getName(),
                "Number of entries " + jsonArray.length());
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            Log.i(ParseJSON.class.getName(), jsonObject.getString("text"));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public String readTwitterFeed() {
    StringBuilder builder = new StringBuilder();
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet("http://twitter.com/statuses/user_timeline/vogella.json");
    try {
        HttpResponse response = client.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
        } else {
            Log.e(ParseJSON.class.toString(), "Failed to download file");
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return builder.toString();
}

Add Following permission to your manifest file

android.permission.INTERNET
Yash
  • 1,751
  • 13
  • 14
0

That tastes like JSON, right ? How about using a JSONObject to parse it:

JSONObject jsonResponse = new JSONObject("...");
sdabet
  • 18,360
  • 11
  • 89
  • 158