Jump to content

Retrieve single field from json string field


karin_1
Go to solution Solved by zellers,

Recommended Posts

I have a string field with the following data:
{"vin":"VIN4","brand":"Merk4","type":"Type4","year":2004}

How can I retrieve the value for the fields vin, brand, type and year and print them in my document?

My string never contains repeating data.

I cannot use query to retrieve the data from the json string (I use Servoy foundset).

Link to comment
Share on other sites

  • 3 weeks later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Solution

Here is some red hot garbage that might do the trick:

$V{Variable_1}.substring($V{Variable_1}.indexOf(""vin":") + new String(""vin":").length() + 1).substring(0,$V{Variable_1}.substring($V{Variable_1}.indexOf(""vin":") + new String(""vin":").length() + 1).indexOf("",""))[/code]

This should return the value for "vin" for data stored in $V{Variable_1}.

 

Yes. I know. This is disgusting. ;-)

 

Update 2022: I'm stupid and this is the proper way to do it:

new org.json.JSONObject($V{JSON}).get("vin").toString()[/code]

 

Link to comment
Share on other sites

Thanks for you reply. It works perfectly. And I managed to make the code even more disgusting :-)
 

$V{Variable_1}.contains("vin")?
$V{Variable_1}.substring($V{Variable_1}.indexOf(""vin":") + new String(""vin":").length() + 1).substring(0,$V{Variable_1}.substring($V{Variable_1}.indexOf(""vin":") + new String(""vin":").length() + 1).indexOf("","")):"no VIN specified"

If the vin field doest not exist, it will not show wrong info. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...