I have a JSON string which looks like this:

jsonstring = {"XX":["Blah blah"]}

I need to get the 'Blah blah' into a string variable. How do I do this?

Tried doing it this way, but all that returned was '{', so that's not working.

string result = (String)JSON.deserialize(jsonstring, String.Class);

Use the JSON.deserializeUntyped to get an Object and you can typecast it further into a Map .

You can then easily start reading the object with key and typecasting it further.

String jsonstring = '{"XX":["Blah blah"]}';

Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(jsonstring);


for(Object o : (List<Object>)m.get('XX')) {
   system.debug((String) o);
  • I tried that as well, but then I get this error: Invalid conversion from runtime type List<ANY> to String. Why would that be? – Irene Apr 9 '19 at 3:46
  • I just fixed it . Sounds like it is array of string and hence you need an array . Check it out . – Mohith Shrivastava Apr 9 '19 at 3:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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