0

im working in NFC reader that accept a json string

when i post the json string thru input text it is accepted:

socket.emit('pushTagInfo', $('#m').val()); 

but when i try to assign it to variable and send it like this:

var jsonform = '{ "patientId": "1111111111111111112\n", "timestamp": "Fri Sep 11 01:18:54 2015\n", "name": "Patient Name\n", "tel": "01*-*******\n", "center": "Center 1\n", "blood": "Blood Group\n", "infection": "none\n" }'; socket.emit('pushTagInfo', jsonform); 

the error is: [SyntaxError: Unexpected token]

what do u think is the problem?

thanks

2 Answers 2

2

You have to escape \ to \\(double slash), otherwise the string won't be a valid json string (\n is new line which break it).

Sign up to request clarification or add additional context in comments.

Comments

0

Is it possible to use an object rather than a string?

var jsonform = { patientId: "1111111111111111112\n", timestamp: "Fri Sep 11 01:18:54 2015\n", name: "Patient Name\n", tel: "01*-*******\n", center: "Center 1\n", blood: "Blood Group\n", infection: "none\n" } socket.emit('pushTagInfo', jsonform); 

1 Comment

no, it accepts only this format { "patientId": "1111111111111111112\n", "timestamp": "Fri Sep 11 01:18:54 2015\n", "name": "Patient Name\n", "tel": "01*-*******\n", "center": "Center 1\n", "blood": "Blood Group\n", "infection": "none\n" }

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.