karin_1 Posted July 21, 2021 Share Posted July 21, 2021 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 More sharing options...
Solution zellers Posted August 11, 2021 Solution Share Posted August 11, 2021 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 More sharing options...
karin_1 Posted August 12, 2021 Author Share Posted August 12, 2021 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now