0

I've been assigned in my college to make an work without any preparation and i don't have any idea on how to use JSON correctly to read this:

{ "af": [
 ["a", "b", "0", "1"],
 ["0", "1"],
 [ ["a","#","0"], [a,0,b], [a, 1, a], ["b", 0,"a"], ["b", "1", "b"], ["0", "0", "0"], ["0", "1", "1"], [1,0,1], [1 ,1, 0] ]
 ["a"],
 ["1"]
 ]
}

I've tried looking into some examples in the internet but no clue into how to use this. I'm trying to make this assignement with java and i was using the Json library json-simple. Could someone help me ? Like really no clue. I'll keep searching more examples.

Mainly my problem would be that to "have" parts of this json i would have to use jsonObject.get("name of stuff"); but the only name i have to use in this function is the "af" ... and dammit i can't out-think this, is Af an array of arrays ? is it a List ? i'm kindda stuck in here.

2 Answers 2

1

Your json text is invalid, because it contains unquoted keys/values.

you have two ways to work with this bad formatted json text:

First

you should first turn your json to a valid json that every character(s) or string should be placed in double quotes. i.e.

this is invalid : [a, 1 ,b]

this one is valid: ["a", 1, "c"]

note: character(s) that i mentioned is anything except numbers

then you can call jsonArray.getJsonArray(n).getJsonArray(m) recursively to get nested arrays where n and m are indices.

Second

use Jackson Core Library features like ALLOW_UNQUOTED_FIELD_NAMES that allows you to parse json texts that are not quoted well. see this answer too

Sign up to request clarification or add additional context in comments.

Comments

0

af is a json array, so you probably should use jsonObject.getJsonArray("af"). That would give you a JsonArray object which you can read using something like jsonArray.getJsonArray(0).getString(0) (you probably would need to find out the value types at runtime with JsonValue.getValueType though).

1 Comment

Wow thnks, that actually, really helps a lot men, real tnks i will try to run it here and get their values types.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.