-3

I have a json like this:

"[
    [\"DBS\",1,[
                [1,1,1,\"A\",\"C\",1],
                [1,2,1,\"B\",\"C\",0]
             ]
    ],
    [\"DBS\",2,[
                [1,1,1,\"A\",\"C\",1],
                [1,2,1,\"B\",\"C\",0]
             ]
    ]
]"

I want to mapping this string to object java,Please tell me how to do?

I've already use this tips, but didn't work. How to convert string array to object using GSON/ JSON?

  • 1
    *why* didn't that work? As is, your question is a duplicate of the one you linked to. – Jorn Aug 04 '23 at 07:57
  • @Jorn There is error like this java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 1 column 12 path $[0][2] – Aditya Rahman Sidqi Aug 04 '23 at 08:00
  • OK, you should add all relevant code and full error messages to the question, otherwise how do you expect us to know what's wrong? – Jorn Aug 04 '23 at 08:01
  • Gson gson = new Gson(); Type type = new TypeToken>() {}.getType(); List yourList = gson.fromJson(stringResponse, type); – Aditya Rahman Sidqi Aug 04 '23 at 08:04
  • com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 1 column 12 path $[0][2] at com.google.gson.Gson.fromJson(Gson.java:939) at com.google.gson.Gson.fromJson(Gson.java:892) at com.google.gson.Gson.fromJson(Gson.java:841) – Aditya Rahman Sidqi Aug 04 '23 at 08:05
  • 1
    To the **question**, not a **comment**. But OK, you do have a problem here. You are trying to parse a `List` and getting an error message that tells you something in the JSON isn't a String, but a `BEGIN_ARRAY` aka a `List`. Looking at the JSON you posted, can you tell what that is? – Jorn Aug 04 '23 at 08:06
  • In addition to what @Jorn wrote; do you really need a `List` or just want to parse it in some way that allows you to access the values afterwards? In that case maybe give `gson.fromJson(stringResponse, JsonArray.class)` a try. – Marcono1234 Aug 04 '23 at 22:23

0 Answers0