Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I've been stuck hours on this supposedly dummy problem.
I am getting data from an hardware device via bluetooth, and after decoding it with :
const int8View = new Uint8Array(data)
const decoder = new TextDecoder('utf-8')
const toParse = decoder.decode(int8View)
I can get a json string that i can print:
console.log("should be parsed ", toParse)
-> should be parsed – "{\"timeStamp\":1580011546,\"startState\":2,\"endState\":3}"
but when I use JSON.parse on this object I get:
SyntaxError: JSON Parse error: Unrecognized token ''
As often when you take time to clearly explain your problem, you find the solution. As I have found nothing on the matter, I give my answer.
If you copy paste the double quote of the error message in an hidden character view like this one it will show you that there was an hidden null \x00 character inside the string.
I removed it with:
toParse.toString().trim().replace(/\0/g, '')
which solved my problem.
Hope this helps others.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I have a string object in javascript as given below:
time : "YYYY-MM-DDT00:00:00.000Z#YYYY-MM-DDT23:59:59.999Z"
When I use JSON.stringify to convert the object to string, I get the following string
"time=YYYY-MM-DDT00%3A00%3A00.000Z%40YYYY-MM-DDT23%3A59%3A59.999Z"
Here 2 characters, i.e., # and : are being converted to their unicode, which is unwanted behaviour.
How can I prevent this unwanted conversion, so that my string remains unchanged?
I can't reproduce your problem, can you show the complete code where the error occurs.
Also, try doing this conversion on the browser console and see what the result comes out to be.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm getting an Uncaught SyntaxError: Unexpected string error, yet when I look at the source, as far as I can tell, it's correct. I can't see any missing commas or quotation marks. Any one have any tips?
(yes, I've searched to see if I can find the problem, but it always seems to be quotation marks and commas)
Thanks
You need to add a pair of square brackets to contain the entries
For example,
let StandardsData = [
{
// stuff
},
{
// stuff
},
{
// stuff
},
]
You missed to close between [ ] that array
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I make an API call and get returned some JSON. I then parse this JSON using
var json = $.parseJSON(result);
To get to the level I need to within this json object, I do something like this
console.log(json.data[0].value)
That will print something like the following to the console
Option "1166325"
Option Two "3329076"
So if I do
console.log(json.data[0].value.Option)
I am printed out 1166325. If however I do
console.log(json.data[0].value.Option Two)
I get an error SyntaxError: missing ) after argument list. I have also tried
console.log(json.data[0].value.['Option Two'])
But this returns SyntaxError: missing name after . operator
So how can I access this data considering there is a space in the name?
Thanks
Yes, just lose the . character:
console.log(json.data[0].value['Option Two'])
This is known as bracket notation and can always be used to access a property. Dot notation can only be used when the property name is a valid Javascript identifier. This means (a) letters and numbers; (b) _ underscores; (c) $ dollar signs.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I need to use the following regex in my Javascript code:
/\D*(\d+)\s*([TGMkmµnp]).*/g
However, the µ symbol is causing syntax error.
How can I fix this?
The error message is:
At "value = str.replace(/(+)(TGMk"
error110: SYNTAX ERROR while lexing character "µ".
I am using TestComplete software.
My code is as simple as this:
function GetVoltageDbl(str)
{
var value = str.replace(/\D*(\d+)\s*([TGMkµmnp]).*/g, "$1");
var prefix = str.replace(/\D*(\d+)\s*([TGMkµmnp]).*/g, "$2");
Log.Message(value);
Log.Message(prefix);
}
Try replacing µ with \u03BC as follows:
/\D*(\d+)\s*([TGMkm\u03BCnp]).*/g
Please try this \µ . It's need to help
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
there is a syntax I can't figure out.
$(this).append(free);
And here is the error message in the console:
Uncaught SyntaxError: Unexpected token <
I have no idea, what this error message wants to tell me, because it makes no sense to me.
Simple, you are missing quotes:
$(this).append('free');
From the docs the parameter you pass can be:
"DOM element, array of elements, HTML string, or jQuery object to insert at the end of each element in the set of matched elements."
$(this).append('free');