首页 > 解决方案 > API 字符串不返回值

问题描述

我正在尝试使用 volley 在 kotlin 中获取 API,但是一旦我尝试从对象中获取字符串,我什么也没有返回:W/System.err: org.json.JSONException: No value for burn

这是 API:

"requested_information": [
    {
      "level": 1,
      "character": "一",
      "kana": "いち",
      "meaning": "one",
      "user_specific": {
        "srs": "burned",
        "srs_numeric": 9,
        "unlocked_date": 1464639834,
        "available_date": 0,
        "burned": true,

try {
                    val jsonArray = response.getJSONArray("requested_information")

                    for (i in 0 until jsonArray.length()) {
                        val jsonObject = jsonArray.getJSONObject(i)

                        // Append character to textView here
                        val cha = jsonObject.getString("character")
                        val burn = jsonObject.getString("user_specific")
                        val burn2: Boolean = jsonObject.getBoolean("burned")

标签: androidapikotlin

解决方案


推荐阅读