Jump to content

Using variables in llJsonGetValue


GloriaGlitter
 Share

You are about to reply to a thread that has been inactive for 1410 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I've started experimenting with bringing in live data via API calls to external services, particularly those that present their output in json format.  This is to provide extra functionality to my AI bot.

So far I've got live weather reports working very nicely.  Currently I'm working with live currency exchange rates.

My question is can I use a string variable in my  llJsonGetValue statement in place of a value?

To explain further, after the http call, variable  'body' is set to  {"rates":{"USD":1,"AED":3.67,"ARS":78.93,"AUD":1.38,"GBP":0.761,"GTQ":7.78,"HKD":7.75,"HRK":6.37}}  (actual list has over 100 currencies)

Variable  'exchange_curr' is set to whatever currency the user is interested in, e.g. "GBP".

rate = llJsonGetValue( body, ["rates", "GBP"])  gives the desired result whereas rate = llJsonGetValue( body, ["rates", exchange_curr]) fails to provide a result. 

Does it always have to be actual data like "GBP" in the json expression and not a variable like 'exchange_curr' that holds this data?

Link to comment
Share on other sites

It's hard to make any definitive conclusions without seeing the involved code, but most likely, exchange_curr is not actually set correctly.

Functions can't know whether they've been given a variable or its data, there's no distinction in LSL.

This works, for example:

string json = "{\"rates\":{\"USD\":1,\"AED\":3.67,\"ARS\":78.93,\"AUD\":1.38,\"GBP\":0.761,\"GTQ\":7.78,\"HKD\":7.75,\"HRK\":6.37}}";
string exchange_curr = "GBP";

llOwnerSay(llJsonGetValue(json, ["rates", exchange_curr]));

 

Edited by Wulfie Reanimator
  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1410 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...