Hello,
I am new to LiveCode, long history of writing just about everything else, so my thought processes are more class oriented and \" is how you put a double quote into a string, been that way for 50 years, where did \q come from?
So it took me a while to find a way to input a JSON sample string into LiveCode.
Reading a text file works best - don't have to fart around with quote games.
local myText;
local theFilePath;
answer file "A text file"
if it <> "" then
put it into theFilePath
put URL ("file:" & theFilePath) into myText
end if
Now that I have a sample JSON string stuck into LiveCode, I did the following:
local tArray;
put JsonImport(myText) into tArray;
OK, now I have some unknown structure in tArray.
In the debugger I can see:
Now how do I access the pieces of whatever it is that is?
Thanks,
Andrew
Accessing JSON output
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 118
- Joined: Thu Sep 20, 2012 5:11 pm
-
- VIP Livecode Opensource Backer
- Posts: 9867
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Accessing JSON output
The User Guide included with LiveCode (see the Help menu) has a very good discussion on learning to use arrays, beginning on page 120.
An an example, to get the value of the accountID key of the first account:
An an example, to get the value of the accountID key of the first account:
Code: Select all
get tArray["AccountListResponse"]["Accounts"]["Account"][1][accountId]
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 7266
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Accessing JSON output
Good question, it isn't LC. I think you've found a custom function that many people use to avoid excessive concatenation in scripts. The one-line function just returns a given string with quotes around it. It improves readability.where did \q come from?
The \" syntax is used in LC when constructing several things, like any command or function that uses regex expressions (merge comes to mind, as well as matchtext, etc.) Even menu items use a backslash to force an exact character match if the character is one that indicates menu text styles.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 722
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Accessing JSON output
Also take a look at Andy's brand new post on a JSON plugin for this purpose (JSON Api Helper plugin).
The code will also help to learn about JSON and Arrays.
viewtopic.php?f=4&t=34434&p=194462#p194462
The code will also help to learn about JSON and Arrays.
viewtopic.php?f=4&t=34434&p=194462#p194462