0
I’m trying to send a file .json
created within Angular for a server, and gives this error as a response:
"A Jsonobject text must Begin with '{' at 1 [Character 2 line 1]", object_or_array: "Object", error_info: "This error came from the org.json Reference parser." , validate: false}"
It’s just going to the URL, without the JSON, by the way. Below is the code, made in angular:
var json={
usuario : this.nome,
senha : this.senha
};
var myJson=JSON.stringify(json);
console.log(json);
return this.http.post(this.url,JSON.stringify(json))
.map(res=> res.json())
.subscribe(data =>{
console.log(data);
});
If I’m not mistaken, you don’t need to string json to function
http.post
, just passing the object straight.– edson alves
Like this: ---Return this.http.post(this.url,JSON.stringify({user : this.name, password : this.password}))---? I tried and gave another error
– Matheus Rodriguez
No, just replacing
JSON.stringify(json)
forjson
– edson alves
No need to convert to json, and please post the code instead of image https://pt.meta.stackoverflow.com/questions/5483/manual-de-como-n%C3%83o-ask-questions
– Eduardo Vargas
i replace JSON.stringify(json) with just json and keep giving the same error. I would have a way to see the output json from the browser console?
– Matheus Rodriguez