Using Raw clause wiht in Java , query result retrives Arraylist with in String

Hi CB Team,
While using RAW META() clause, to fetch list of order id , the N1qlQueryResult retives the ArrayResult with in the String / wrapped with String , do you know how we can put into ArrayList.

N1qlQueryResult : “[“019999310850”, “02970340053”, “0397056733”, “04908626533”]”

ResultResponse look like for one raw as bewlow

index[0] - > "“019999310850"” - two inverted comma front of the each value
asynRow - Value = null ,
byteValue= 9551

[
“019999310850”,
“02970340053”,
“0397056733”,
“04908626533”
]

Hi Mehul,
Looks like you’ve got a JSON array. You could parse it using com.couchbase.client.java.document.json.JsonArray, like this:

String jsonString = "[\"019999310850\", \"02970340053\", \"0397056733\", \"04908626533\"];
JsonArray jsonArray = JsonArray.fromJson(jsonString);
for (int i = 0; i < jsonArray.size(); i++) {
    System.out.println(jsonArray.getString(i));
}

Alternatively, you could use Jackson for parsing:

ObjectMapper mapper = new ObjectMapper(); // can be static final
List<String> list = mapper.readValue(jsonString,
        new TypeReference<List<String>>(){});
System.out.println(list);

Thanks,
David

1 Like