-1

Hi I have below string and I have to split and put in a map . While splitting through string tokenizer or .split method i am not getting the result i want.Below is my string

{"errorCode":"specialChars.allowed","errorParams":["a-zA-Z0-9^][_{|}=~!\"#$%&()*+,-.:'\\/?@space"]}

I want

 Key:errorCode Value:specialChars.allowed 
Key:errorParams Value:[
  "a-zA-Z0-9^][_{|}=~!\"#$%&()*+,-.:'\\/?@space"
]

1 Answers1

1

Since your input String is a JSON String, you can use Gson API to convert it into a Map.

String str = “{‘errorCode’:’specialChars.allowed’,’errorParams’,’[“a-zA-Z0-9^][_{|}=~!\"#$%&()*+,-.:'\\/?@space”]’}”;
Type type = new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> myMap = new Gson().fromJson(str,type);
Sahil Chhabra
  • 10,621
  • 4
  • 63
  • 62