kurtn718
12 years agoVisitor
Built-in ToJSON function
Hi. Is there a built-in ToJSON function, similar to ParseJSON?
I couldn't find one in the docs, but I was able to write the following function taking an roAssociativeArray as the input - which works for what I need.
If there is a built-in function, I'll probably replace the code below with that function. If one doesn't exist, then this is my first contribution to the forum. 🙂 If there is a way to write the code better, please offer suggestions.
Thanks,
Kurt
-------
Function ToJSON(jsonData as Object) as String
jsonRequest = "{"
for each key in jsonData
if jsonRequest <> "{" then
jsonRequest = jsonRequest + ","
endif
jsonRequest = jsonRequest + chr(34) + key + chr(34) + " : " + chr(34) + jsonData[key] + chr(34)
end for
jsonRequest = jsonRequest + "}"
return jsonRequest
End Function
I couldn't find one in the docs, but I was able to write the following function taking an roAssociativeArray as the input - which works for what I need.
If there is a built-in function, I'll probably replace the code below with that function. If one doesn't exist, then this is my first contribution to the forum. 🙂 If there is a way to write the code better, please offer suggestions.
Thanks,
Kurt
-------
Function ToJSON(jsonData as Object) as String
jsonRequest = "{"
for each key in jsonData
if jsonRequest <> "{" then
jsonRequest = jsonRequest + ","
endif
jsonRequest = jsonRequest + chr(34) + key + chr(34) + " : " + chr(34) + jsonData[key] + chr(34)
end for
jsonRequest = jsonRequest + "}"
return jsonRequest
End Function