如何在StringBuilder中将项目与JsonObject分开?

时间:2014-04-15 14:13:37

标签: java android stringbuilder jsonobject

这是我的代码:

                    BufferedReader reader = new BufferedReader(new InputStreamReader(
                            inputStreamObjectValue));

                    StringBuilder sb = new StringBuilder();
                    String line = null;
                    // Read Server Response
                    while ((line = reader.readLine()) != null) {
                        // Append server response in string
                        sb.append(line + "\n");

                    }
                    Log.e("values :",sb.toString());

当我运行时,然后记录打印

{"Status":1,"SessionId":"ulrvmysxrmha14t0cd031upp6yluh69amgfub02j78lubcht5i"}

如何分开item.Such

Status=1 and SessionId="ulrvmysxrmha14t0cd031upp6yluh69amgfub02j78lubcht5i";

请帮帮我。

1 个答案:

答案 0 :(得分:2)

使用此:

try {
    JSONObject job = new JSONObject(sb.toString());
    int Status = job.getInt("Status");
    String SessionId = job.getString("SessionId");
} catch (JSONException e) {
    // Handle error
}

参考:http://developer.android.com/reference/org/json/JSONObject.html