Giter VIP home page Giter VIP logo

Comments (4)

bndr avatar bndr commented on August 30, 2024

You don't really navigate the JSON, the JSON object ist loaded into your response Structure

Example:

type UserExample struct {
    Id            string
    Name          string
    Origin        string
    Url           string
    SomeJsonField string
}

// Create Basic Auth
auth := gopencils.BasicAuth{"username", "password"}

// Create New Api with our auth
api := gopencils.Api("http://your-api-url.com/api/", &auth)

// Create a pointer to our response struct
resp := &UserExample{}

// Perform a GET request
// URL Requested: http://your-api-url.com/api/users/1
// The JSON data is loaded into resp variable
api.Res("users", resp).Id(1).Get()

// Now your Response Struct (resp) contains the parsed JSON, you can now access the properties.

from gopencils.

tlianza avatar tlianza commented on August 30, 2024

Ah - thanks... so if it's a more complex payload, with a header that has some meta information, then a body that might have an array of structures, one would need to create a struct that maps all of those values?
api_popshops_com_v3_merchants_json_account_5j442sbofhecuy31lk8gketk8

from gopencils.

bndr avatar bndr commented on August 30, 2024

Basically yes, you can use the json-to-go struct service e.g. http://mholt.github.io/json-to-go/ to generate the struct, then use that struct to store the response.

On 02 Apr 2015, at 19:07, Tom Lianza [email protected] wrote:

Ah - thanks... so if it's a more complex payload, with a header that has some meta information, then a body that might have an array of structures, one would need to create a struct that maps all of those values?


Reply to this email directly or view it on GitHub.

from gopencils.

tlianza avatar tlianza commented on August 30, 2024

This is perfect - thank you!

from gopencils.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.