Comments (6)
You no need to call json.Unmarshal
manually. resty does it for you automatically based content type JSON or XML otherwise resty won't do any. Will keep your response body intact.
you might have saw the example, I gave you.
var a MyStruct
res, err := resty.R().SetResult(&a).Get(....)
// just print it, you will see your values
fmt.Printf("\n%#v\n", res.Result().(*MyStruct))
from resty.
Now 2019, the example code above should put in README.md. Without this issue and the code, I have no ideas what to do.
from resty.
@miqui Please have a look resty_test.go. You will find more examples.
Automatic marshaling & unmarshalling example:
- https://github.com/go-resty/resty/blob/master/resty_test.go#L196
- https://github.com/go-resty/resty/blob/master/resty_test.go#L239
- https://github.com/go-resty/resty/blob/master/resty_test.go#L331
from resty.
@jeevatkm , thanks for the reply,
i am doing this:
res, err := resty.R().Get(....);
var a MyStruct
json.Unmarshal(res.Body(),&a)
so that i can then inspect the a struct properties, ... i was not sure what you meant by "automatic" unmarshalling...
t.Logf("Response Body: %v", resp)
i need to be able to check attributes of the resp JSON
from resty.
cool, let me try that...
...it worked thanks!
from resty.
I'm glad to hear that. Thanks.
from resty.
Related Issues (20)
- [BUG] DigestAuth with SetBody will be 'http: ContentLength=54 with Body length 0' HOT 3
- SetResult replaces nested struct with a map inside a map HOT 1
- Resty client global variable HOT 1
- parseResponseBody > Unmarshalc cannot unmarshal string into Go value of type map[string]interface {}
- DATA RACE in resty's middleware (go-resty/resty/v2.releaseBuffer()) HOT 2
- What's the idiomatic way of changing proxies for the client? HOT 1
- Add support for go-logr/logr on resty HOT 1
- Is the `SetTimeout()` respected by the default context?
- Request body is written multiple times HOT 2
- Result value has been set and parsed correctly and the request returns successfully, the correct address cannot be recognized HOT 2
- support OnBeforeResponse HOT 1
- setTimeout does not take effect HOT 2
- memory leak when response is too large HOT 2
- SetRetryCount() on request? HOT 1
- It seems memory leaks with post HOT 3
- Call to http.DetectContentType has trailing NUL bytes in buffer HOT 1
- The SetContentLength(boo) method may cause an out-of-memory issue when uploading large files, such as 5GB. HOT 1
- CVE-2023-45286 HOT 3
- Breaks application from Ctrl-C handling HOT 1
- Brotli support HOT 1
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 resty.