Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch res.json() SyntaxError: Unexpected token  in JSON at position 0 #26523

Closed
YanYuanFE opened this issue Sep 21, 2019 · 8 comments
Closed
Labels
Bug 🌐Networking Related to a networking API. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@YanYuanFE
Copy link

YanYuanFE commented Sep 21, 2019

React Native version: 0.60.5 and 0.59.3

Steps To Reproduce

  1. use fetch report error but worked on browser

Describe what you expected to happen:
res.json() work.

Snack, code example, screenshot, or link to a repository:

fetch('http://minisite.medtoday.com.cn/cycle/v-tipr-physician/getcolumnbycompanyid.php?company_id=1&parent_id=0').then(res => res.json())
    .then(res => {
      console.log(res);
    })
@YanYuanFE YanYuanFE added the Bug label Sep 21, 2019
@YanYuanFE
Copy link
Author

image

@react-native-bot react-native-bot added the 🌐Networking Related to a networking API. label Sep 21, 2019
@YanYuanFE
Copy link
Author

res.text() can work, but JSON.parse() for after res.text(), also not work.

@JKCooper2
Copy link

Have you confirmed the response status is 200? Try using the code from https://developers.google.com/web/updates/2015/03/introduction-to-fetch#fetch and see if that prints it out

@YanYuanFE
Copy link
Author

response status is 200, but response header not status 200, is this reason?

@JKCooper2
Copy link

Not sure, however i believe its an issue with fetch you're having, not an issue with react-native

@ravirajn22
Copy link

This error is not related to fetch or react-native i think. Print the raw body text from the response and check if you can parse it to json in chrome dev tools. Most probably the issue is due to response body not in proper format to parse to json.

@stale
Copy link

stale bot commented Dec 22, 2019

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 22, 2019
@stale
Copy link

stale bot commented Dec 29, 2019

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Dec 29, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Dec 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug 🌐Networking Related to a networking API. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

4 participants