Jump to content

JSON.parse on String Variable

Recommended Posts

I am try to clean up a JSON string from

{"v":"this is sample text"}

with the aim of obtaining the text value:

this is sample text


I have tried JSON.parse as follows, but it doesn't seem to work

string_value := JSON.parse('"'+string_value+'"'); 


What is the correct way of doing this?

Link to post
Share on other sites

Hi @COMFIED, I'm not sure if the following answers your question or not.

Add System.JSON to your uses clause and run the following. Some follow up questions would be, is the object you are passing always a single key/value pair and is the name of the key known or not known? There are many ways to do this; some type safe, others not - just depends on your use case really.

  aString : String;
  anObject : variant;
  aString := '{"v" : "this is sample text"}';
  anObject := TJSON.parse(aString);


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...