1

我正面临 json 错误,虽然

System.out.println((int)text.trim().charAt(0));

返回 123,这意味着它确实以大括号开头。我完全没有想法,我也试图trim()代替toString().

InputStream bis = new ByteArrayInputStream(bytes);
InputStream is = new GZIPInputStream(bis);
byte[] unPackedBytes = IOUtils.toByteArray(is);
String text = new String(unPackedBytes, "UTF-8");
JSONObject obj = new JSONObject(text.toString());

这太奇怪了,因为当我输入 json 时它没有给出任何错误但是当我给出压缩文件时它确实给出了错误但是压缩文件的输出与 json 完全相同,所以我很困惑。这是Json。

{
    "id": 123,
    "providerId": 123,
    "externalTrackId": "068d",
    "genres": [
        {
            "genre": "Rap/Hip-Hop",
            "subGenre": "Rap/Hip-Hop"
        }
    ],
    "title": {
        "title": "The "
    },
    "artists": [
        {
            "name": {
                "primary": {
                    "value": "J-"
                }
            },
            "role": "Artist"
        }
    ],
    "contributors": [],
    "release": {
        "id": 123,
        "title": {
            "title": "The "
        },
        "artist": {
            "primary": {
                "value": "J"
            }
        },
        "externalId": "gener2cec9477d",
        "genre": {
            "genre": "Rap/Hip-Hop",
            "subGenre": "Rap/Hip-Hop"
        },
        "copyrightYear": 0
    },
    "trackCountInMedia": 0,
    "mediaCountInRelease": 0,
    "signature": {
        "url": "https:",
        "id": 123,
        "type": "FULL",
        "audioType": "MUSIC",
        "creation": "2013-"
    },
    "label": "Unknown",
    "lastMod": "2013-01-04T16:02:57.607Z"
}

干杯

4

1 回答 1

0

我找到了答案,这是我的错误,因为我没有从 Base64 解码数据。这很奇怪,因为它看起来像完全相同的输出,但事实并非如此。

感谢@Jhanvi 试图帮助我。

于 2013-10-28T08:59:53.273 回答