Retrieve single field from json string field

0

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).

karin_1's picture
Joined: Feb 22 2017 - 4:45am
Last seen: 7 hours 56 min ago

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. 

karin_1 - 1 month 1 week ago

1 Answer:

1

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("\",\""))

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

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

zellers's picture
59
Joined: Feb 12 2019 - 11:18am
Last seen: 1 week 5 days ago
Feedback