【问题标题】:Android && JSON: Changing JSON Response Message to Plain Text [closed]Android && JSON:将 JSON 响应消息更改为纯文本 [关闭]
【发布时间】:2013-10-31 06:59:20
【问题描述】:

我在 android logcat 中以 Json 编码格式很好地获得了 JSONResult,我必须更改 Json 响应 message to simple plain text 并在编辑文本字段中显示给用户。

我收到的响应消息是这样的。

3{"success":0,"message":"糟糕!预约已满"}

请帮帮我。

【问题讨论】:

标签: android json


【解决方案1】:

如果需要获取成功消息的字符串值

JSONObject jObject new JSONObject(jString);// jString is your string response

int successValue = jObject.getInt("success");
String messageValue= jObject.getString("message");
// you can cast successValue to string
String successStringValue = String.valueOf(successValue);

【讨论】:

    【解决方案2】:
        JSONObject json = new JSONObject(yourStringResponse);
        String message = json.getString("message");
        yourEditText.setText(message);
    

    【讨论】:

      【解决方案3】:

      将您收到的响应隐藏为字符串,例如 String result1 = responsemessage.toString();

      试试这个

      JSONObject someObject = new JSONObject(result1);

      JSONArray Jarray = Jarray.getInt("success");
      

      JSONArray Jarray = Jarray.getString("message");'

      因为你得到的是一个 json 对象而不是 json 数组

      【讨论】:

      • 感谢回答,但给出异常 {"success":0,"message":"Oops!Appointment Full"} 类型的 orgjson.jsonobject 无法转换为 jArray
      • getJSONArray 不适用于 String 对象...
      猜你喜欢
      • 2014-07-18
      • 2023-03-10
      • 2011-06-02
      • 1970-01-01
      • 2015-09-09
      • 2011-04-22
      • 2018-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多