JSON.stringify converts colon inside string to a unicode character [closed] - javascript

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.

Related

JSON parse error with double quote as unrecognized token [closed]

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.

Is this is a Javascript's substring bug or am I missing something? [closed]

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
This is a screenshot from my Chrome browser console window (running in Chromes OS 72.0.3626.97).
substring(0,1) works as expected, but (1,1) does not, whereas .charAt() consistently produces the expected result and, as shown, is not in sync with substring after the (0).
There is no character between indexes 1 and 1 in the string.

Syntax Error jQuery [closed]

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');

Firefox returning incorrect JSON using JQuery [closed]

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
I am trying to make a post to an API endpoint. It seems to work in safari and chrome even ie. But firefox seems to want to add a double quote to the beginning and end of the json string. I dont know that this is a huge issue to most of the community but I am under deadline and this is the only thing keeping me from hitting my target.
console.log(JSON.stringify($('FooObject').serializeObject()));
This returns
"{"key":"value"}"
I need
{"key":"value"}
Any suggestions? I have trolled the net for about 3 hours and no dice.
Please be nice I do not do js often, more than often I do networking and security this is a edge case that I need tackled.
Thank you in advance.
If the double quotes display in the Firefox console- then quotes are just to signify that it's a string.

Javascript .charAt(0) gives unexpected results [closed]

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 8 years ago.
Improve this question
var category = "a()";
if(category.charAt(0) == /^[a-zA-Z]+$/){
/*This part doesn't gets executed*/
/*What is the problem with the if condition?*/
}
You are comparing your character with an instance of a regular expression.
You actually want to test your character with the regular expression.
You can do that like this:
var category = "a()";
if (/^[a-zA-Z]+$/.test(category.charAt(0))) {
// Now it will get executed
}
Further reading on JavaScript regex flavor:
http://www.regular-expressions.info/javascript.html

Categories

Resources