0

Assigning HTTP data source to an array

I am fetching from a URL with the http() function and getting this result:

let vSrc := text(http("GET","http://bareawe.net/work/gp/noon/pos.txt","",""))

=>

{"result":"$GPGGA,181908.00,3404.7041778,N,07044.3966270,W,4,13,1.00,495.144,M,29.200,M,0.10,0000*40"}

After some text manipulation I'm left with a series of strings that I would like to place in an array like so:

"$GPGGA","181908.00","3404.7041778","N","07044.3966270","W","4,13,1.00,495.144","M","29.200","M","0.10,0000*40"

let aData := [vGPS]

The problem is that I see nothing when trying to retrieve an element of the array i.e. I would expect item(aData,3) to return "N" but it returns nothing. Here's my code:

let vSrc := text(http("GET","http://bareawe.net/work/gp/noon/pos.txt","",""))
let vGPS := replace(vSrc,"{""result"":""","");
let vGPS := replace(vGPS,"""}","");
let vGPS := replace(vGPS,",",""",""")
let vGPS := lpad(vGPS,length(vGPS)+1,"""")
let vGPS := rpad(vGPS,length(vGPS)+1,"""")
let aData := [vGPS]
item(aData,3)

4 replies

null
    • Birger_H
    • 6 yrs ago
    • Reported - view

    Versuchen Sie es so:

    –––
    let aData := unique("a", "b", "c", "d");
    item(aData, 2)
    –––

    Rückgabe ist "c" :-)

    Birger

    • Thad_Robertson
    • 6 yrs ago
    • Reported - view

    Vielen Dank :)

    • Thad_Robertson
    • 6 yrs ago
    • Reported - view

    hmmm.. this works is aData is populated as shown in your example, but not if it assigned from a varible such as vGPS in my example above. vGPS = "$GPGGA","181908.00","3404.7041778","N","07044.3966270","W","4,13,1.00,495.144","M","29.200","M","0.10,0000*40"

    • Thad_Robertson
    • 6 yrs ago
    • Reported - view

    It seems the return from the http() call is an object in the form of ["name":"value"]  My problem is that I can't seem to find a way to turn the result comma separated result into elements of an array. unique() does not work either. Is there a way to change the data type to make this work? Here's my code:

    let vSrc := http("GET","http://bareawe.net/work/gp/noon/pos.txt","","")

    => vSrc: {"result":"$GPGGA,181908.00,3404.7041778,N,07044.3966270,W,4,13,1.00,495.144,M,29.200,M,0.10,0000*40"}

    let oRes := [first(first(vSrc).result)]
    let tRes := text(oRes)
    let tRes := replace(tRes,",",""",""")
    let tRes := replace(tRes,"""","""")
    let tRes := replace(tRes,"[","")
    let tRes := replace(tRes,"]","")
    let aRes := []
    let aRes := [tRes]

    => aRes: "$GPGGA","181908.00","3404.7041778","N","07044.3966270","W","4,13,1.00,495.144","M","29.200","M","0.10,0000*40"

Content aside

  • 6 yrs agoLast active
  • 4Replies
  • 2099Views