calling an api from a stack?

Mike Bonner bonnmike at gmail.com
Fri Jun 15 13:40:55 EDT 2018


jsontoarray returns an array, you'll have to dig through the array to find
where pieces of information reside, but it pretty straightforward after you
poke around.

For example.. If you instead do this..
put jsontoarray(tResult) into tArray

you have an array variable named tArray.
If you-- put the keys of tArray you'll see the first level of keys.
One of the keys is named "text" and it has a numeric subkey named 1
So if you-- put tArray["text"][1] into field 1
The translation will be placed into the field.

YOu can use the "put the keys"  syntax to find subkeys too, so if you-- put
the keys of tArray["text"]  you get back the single subkey 1. If you were
to-- put the keys of tArray["text"][1] you would get nothing back because
there are no subkeys.  Instead, a value has been placed into key
["text"][1] which is your translated text.  Its pretty easy to poke around
an array this way and figure things out, especially since the array for
this is pretty simple. (also look at "elements" in the dictionary)

On Fri, Jun 15, 2018 at 11:07 AM Eric A. Engle via use-livecode <
use-livecode at lists.runrev.com> wrote:

> This works, sort of:
>
>   put URL "
> https://translate.yandex.net/api/v1.5/tr.json/translate?key=trnsl.1.1.20180527T091305Z.7f33f9fb3f66f0bb.d573f1d9a6336a981504916600c45f49255938b3&text=hello%20world&lang=en-de"
> into tResult
>   put tResult into card field 1
>   --put JsonImport(tResult) into  tResults
>   --put JsonToArray(tResults) into tProfile
>   put tResult & return into cd fld 1
>   set the itemdelimiter to "["
>   put the last item of tResult after cd fld 1
>
> for some reason JsonImport and JsonToArray return nothing. I can however
> set delimiter to [ and then programmatically delete the first and last 3
> chars after the last item of tResult. But why can't, or how, must I extract
> from Json?
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the Use-livecode mailing list