1

I am facing an error with json , although

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

returns 123 which means it does starts with curly bracket. I am totally out of ideas and i also tried to trim() instead of 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());

It is so weird because when i input the json it doesn't give any errors but when i give the compressed file it does gives errors but the output of the compressed file is exactly same with json, so i am confused. This is the 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"
}

Cheers

6
  • What is 'text' in above code?
    – Jhanvi
    Oct 25, 2013 at 9:42
  • text is coming from inputstream because i am decompressing the file first.
    – Ducaz035
    Oct 25, 2013 at 9:43
  • Please give some text for example for the 'text' from the stream as you said, so that error can be identified.
    – Jhanvi
    Oct 25, 2013 at 9:45
  • I did and still i am facing the same problem.
    – Ducaz035
    Oct 28, 2013 at 8:04
  • Actually, i have just found out that i am having this error while i am trying to give compressed data.
    – Ducaz035
    Oct 28, 2013 at 8:05

1 Answer 1

0

I found my answer , it was a mistake of me because i wasn't decoding data from Base64. It's weird because it was seemed like exactly same output but it wasn't.

Thanks to @Jhanvi for trying to help me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.