LC8 - Stumbling into JSON

Graham Samuel livfoss at mac.com
Mon Jun 13 18:08:49 EDT 2016


Sorry to be a pain, but again in the BMI example for LC 8 there is this function:

function getBMI pHeight, pWeight
    put "http://api.clinicalcalculator.org/bmi?" &  "height_in_m=" & pHeight & "&weight_in_kg=" & pWeight into tURL
    put url tURL into tJSON
    put JsonImport(tJSON) into tArray
    return round(tArray["result"]["value"])
end getBMI

Knowing nothing about JSON, I find this confusing to say the least. I see that the JsonImport uses a URL to get some value(s) based on parameters incorporated in the URL, but what am I to make of the ‘return’ statement? I mean what do the bits in square brackets mean? Where did the names ‘result’ and ‘value’ come from? How would one know the spec of the result returned by a particular ‘JsonImport’ invocation? Are there libraries of these things, or what? How much JavaScript will I have to know to use this kind of functionality?

Feeling stupid.

Graham






More information about the use-livecode mailing list