The mobile has 2 fields viz:
- Button to query the api
- Large text box to display the contents
- JSON Library
- mergJSON
- tsNet
Code: Select all
{
"data": [
{
"id": 1,
"date_created": "2021-11-08T17:12:03Z",
"date_updated": "2021-11-22T16:08:55Z",
"first_name": "Matt",
"last_name": "Damon",
"email": "mattdamon[at]livecode[dot]com",
"phone": "9876543210",
"dob": "1980-01-01",
"password": "xxxxxxxxx",
"plan_start": "2021-11-22T16:07:46Z",
"plan_expiry": "2021-12-21T16:06:25Z"
}
]
}
In my livecode stack:
- The button is named as "getdata"
- The textbox is named as "flddata"
In the button script, when I use the following code, the entire api response above gets displayed in the text box
Code: Select all
put "<api url endpoint>" into tUrl
put "Authorization: Bearer xxxxxxxxx" into tHeaders
put tsNetGetSync(tUrl, tHeaders, tRecvHeaders, tResult, tBytes) into tData
put tData into field "flddata"
But when I add the following code In the button script, I don't see the value of the email key.
Code: Select all
put "<api url endpoint>" into tUrl
put "Authorization: Bearer xxxxxxxxx" into tHeaders
put tsNetGetSync(tUrl, tHeaders, tRecvHeaders, tResult, tBytes) into tData
put JSONToArray(tData) into tDataArray
put tDataArray["email"] into field "flddata"
The above doesn't work. Nothing happens. How do I parse the value of the key "email" from the json response and display it in the text box? For the life of me, I can't figure out what's wrong. Any help would be appreciated. Thanks a ton!