質問

I have a form that needs to collect the values and turn into a JSON query. However, when I use JSON.stringify it removes the zero off any zip code that begins with zero. Is there any way to prevent that?

Here is a simple version of the code I'm trying to use:

var zipcode = 02122;
var data = {
   ZipCode : zipcode
}

var jsonQuery = JSON.stringify(data);
役に立ちましたか?

解決

You're making a fundamental mistake:

Zip codes are not numbers



Numbers are for numeric data – things that you might add or multiply.
Leading zeroes in a number are intrinsically meaningless, and are not stored anywhere.

Zip codes are strings that happen to only contain digits.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top