Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

New Post: eBay API returns JSON as Text

$
0
0
Hi BSalita,

What is the exact Content-Type header string value? You mention 'Text' so I'm assuming it is literally "text". Our extract_json() API checks to make sure it is one of the following values:
application/json
text/json
text/x-json
text/javascript
text/x-javascript
application/javascript
application/x-javascript
I think what you did by changing the Content-Type header to the standard application/json is good idea. There are just a couple things to keep in mind. First you need to be sure the data you are getting back is indeed json, if not obviously we will fail when trying to parse it. Second you need to be careful to not lose any charset information. For example if the Content-Type was "text; utf-16" and you replace it to be "application/json" when we go to parse the data we will assume it is utf-8, as this is the default for application/json if not specified. This means if you take this approach you should make sure to carry the charset portion forward. If you don't want to do this another option would be to get the data as a string and directly construct the json::value object yourself using http_response::extract_string().

As to whether or not this is an Ebay bug, I'm not quite sure. In my opinion yes it would be better if they returned the content type with the standard MIME type application/json.

Let's know if you hit any other issues.
Steve

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>