Comments (4)
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.
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?
from gopencils.
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.
This is perfect - thank you!
from gopencils.
Related Issues (9)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gopencils.