This most probably means the response you are getting from the webserver is not a JSON object, instead, it is an HTML document. Do a console.log of the output you get from res.text() and the rest should be easy to figure out.
Most probably the endpoint you are requesting is wrong, for example in the case of express.js if you request an endpoint that does not exist it would respond with this,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /</pre>
</body>
</html>
I suppose it is similar in Django as well, also if you are saying that you have tried using the response.text() method already, then maybe make sure that the error originates from the part of code you suspect.
Answer from hafizur046 on Stack OverflowAs I’ve seen several members of this subreddit bring up, as of today many people are getting a dreaded piece of text on the bottom of their screen— no, not, “The AI doesn’t know how to respond,” nor is it that goddamn, “Uh oh, this took a weird turn.”
It’s a new piece of text; supposedly an error. I’m unsure of what triggers it, but it’s personally begun impacting me, as well. I go home after a quest, and want more out of my prompt? JSON error. I’m generating an ai-created character? JSON error.
I legitimately cannot play this game anymore.
I feel as if it may be a part of a new update to the filter, personally— however, to my knowledge I didn’t have any keywords to trigger it besides stating the characters’ ages; no swearing, no, “Fuck, my 9-year-old computer broke,” nothing.
But, regardless of the cause, what I know is that it’s by far the worst thing yet. I can live on the edge of my seat with the filter. I can handle a worse Griffin AI. But this is making things absolutely unplayable.
And that’s awful.
I knew that Latitude was digging itself into its own grave, but Jesus Christ.
This most probably means the response you are getting from the webserver is not a JSON object, instead, it is an HTML document. Do a console.log of the output you get from res.text() and the rest should be easy to figure out.
Most probably the endpoint you are requesting is wrong, for example in the case of express.js if you request an endpoint that does not exist it would respond with this,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /</pre>
</body>
</html>
I suppose it is similar in Django as well, also if you are saying that you have tried using the response.text() method already, then maybe make sure that the error originates from the part of code you suspect.
I had the same problem and solved it with a die() after echo json_encode(...) on server side
JSON Parse error: Unrecognized token | OutSystems
JSON Parse error: Unrecognized token'<' - react-native
[Unhandled promise rejection: SyntaxError: JSON Parse error: Unrecognized token ''] with ANDROID platform only
How to solve JSON parse error: Unrecognized token issue in datatables? — DataTables forums
Videos
This Means you are getting Html response from the server probably a 404 or 500 error. Instead of response.json() use response.text() you will get the html in text.
fetch("http:/example.com", {method: "POST",
body: JSON.stringify(
{
uname: uname,
password: password
}
)
})
.then((response) => response.text())
.then((responseData) => {
AlertIOS.alert(
"POST Response",
"Response Body -> " + responseData
)
}).done();
this.props.navigation.navigate("Home")
};
You can try by adding the headers to your fetch api, as it posts your record to your url.
var dataObj = {}
dataObj.uname = uname,
dataObj.password = password
fetch("http:/example.com", {
method: 'post',
headers: {
'Accept': 'application/json, text/plain, */*', // It can be used to overcome cors errors
'Content-Type': 'application/json'
},
body: JSON.stringify(dataObj)
})
.then((response) => response.json())
.then((responseData) => {
AlertIOS.alert(
"POST Response",
"Response Body -> " + JSON.stringify(responseData.body)
)
}).done();
this.props.navigation.navigate("Home")
};
It is probably because your request is returning an HTML instead of a JSON and when you try to parse it, the first char would be <, which is already invalid for a JSON string.
But it is really hard to be sure without you posting the HTTP response from server that you are trying to parse as a JSON or the code you are using to do it.
I had similar error. The error was because of the URL not being encoded. The steps to make it work are
In the server side, I used JSON.stringify and encode like
/login.html?userdetails="+encodeURIComponent(JSON.stringify(res))
and in the client side, the details was obtained by
JSON.parse(decodeURIComponent(params['userdetails']))
The handler is not called because the invalid part is not the property ("two") but the value (nonStandardThing()).
An obvious way to handle this, is to pass nonStandardThing() as a String, i.e. rewrite the JSON document as
Copy{
"test": {
"one":"oneThing",
"two": "nonStandardThing()",
"three": true
}
}
If that is not a possibility, there is not much to do. Using a custom Jackson Deserializer is only useful for properties, not values.
Content you list is unfortunately not valid JSON, so what you have is not really a JSON document, but perhaps serialization of a Javascript object. All String values MUST be enclosed in double quotes in JSON.
Jackson does not support reading of such content directly, but it may be possible to read this using YAML parser like SnakeYAML. Jackson also has YAML data format module at https://github.com/FasterXML/jackson-dataformat-yaml/ so you could perhaps use that. Given that YAML is (mostly!) a superset of JSON, it could probably do what you want.