简体   繁体   中英

Parse Twitter Fabric REST API as JSON string

Twitter's REST APIs are now accessible via Fabric. They used Square's Retrofit internally to get response in java model.

https://docs.fabric.io/android/twitter/access-rest-api.html

According to this link, we can create custom interface for a specific API that we need in our app like this:

// example users/show service endpoint
interface CustomService {
    @GET("/1.1/users/show.json")
    void show(@Query("user_id") long id, Callback<User> cb);
}

https://dev.twitter.com/rest/reference/get/application/rate_limit_status

If we take the above API as an example, they say that API is responded in JSON. The problem is they internally convert json to (Some predefined) java model (like User, Account) that we get in callback. How should we convert json to java object which they dont provide. I want to print Original JSON response . Is there any way to do this?

Any lights in this area?? Thanks.

How do I convert a successful Response body to a specific type using retrofit?

According to this SO post, passed StringConverter and we are done!

You can try changing the Callback<User> to Callback<Object> .
It will print the string representation of the object, instead of { } .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM