gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 05:55:54 24 4
gpt4 key购买 nike

这是我的代码:

                    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"}

如何分离项目。例如

Status=1 and SessionId="ulrvmysxrmha14t0cd031upp6yluh69amgfub02j78lubcht5i";

请帮助我。

最佳答案

使用这个:

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

关于java - 如何在 StringBuilder 中将项目与 JsonObject 分开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23086320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com