#Grabbing certain information from response body

30 messages · Page 1 of 1 (latest)

stone sundial
buoyant stream
#

@stone sundial could u help me figure it out cuz i got now clue how im gonnna get it working:P

stone sundial
#

I don’t have enough info, could you take a look at this blog post and ask a more complete question please? https://kesdev.com/how-to-ask-a-good-question/

Kestrel Development

When you have a problem with a software project or library, often the best way to ask for help is through text. Different projects offer support in different ways, such as email, chat rooms, or GitHub issues. Most of the time, the people helping you out are unpaid volunteers, so

buoyant stream
#

um

stone sundial
#

Notably I need some code, what you’re trying to do, what happens, and what you want to happen

buoyant stream
#

this is what the response looks like

#
{"status":"success","id":"myid","denormalized":{"myid":{"data":{"id":"name","my
name":"mario","gender":"m", "key":87374734}...
``` and blah blah
#

and i want to grab lets say

#

myname

#

or key

stone sundial
#

Nice, what code have you written to try to get that data out?

buoyant stream
#

so first i tried to turn it into a struct

#

and that failed

#

so idk a different way

stone sundial
#

Try the instructions in fastjson

buoyant stream
#

well i did

stone sundial
#

What code did you end up with?

buoyant stream
#
    if err != nil {
        fmt.Println("No response from request")
    }
    defer resp.Body.Close()
    body, _ := ioutil.ReadAll(resp.Body)
    return fastjson.GetString(body, "denormalized", "data")
stone sundial
#

Thanks. Let me try it out locally

buoyant stream
#

kay

crimson sparrow
stone sundial
#

It doesn't look like you followed the fastjson readme closely. You need to call Parse on the JSON raw data first

#

!go

var p fastjson.Parser
v, err := p.Parse(`{"status":"success","id":"myid","denormalized":{"myid":{"data":{"id":"name","my name":"mario","gender":"m", "key":87374734}}}}`)
if (err != nil) {
  log.Fatal(err)
}
fmt.Println(string(v.GetStringBytes("denormalized", "myid", "data", "my name")))
#

The go bot doesn't seem to work here, but this will print out mario

supple crown
#

How dynamic is this json actually?

buoyant stream