I have a variable with the following in my code:
{
"Rows":
[
{
"New":1,
"CachedNumberType":0,
"Date":1327479615921,
"Type":2,
"Number":"123456",
"Duration":1
}
]
}
I think it’s JSON, how do I parse it? (E.g., with json2.js?) Or how do I use it in my JavaScript?
You’ve said that when you try
JSON.parseon the variable containing the “JSON” that it says it can’t parse it. Could it be that it’s already deserialized? Or maybe it was never JSON at all? For instance, what you quoted, in JavaScript source, is an object literal containing an array literal containing another object literal; no JSON in sight.If you do
console.log(x.Rows[0].Date);, wherexis the variable you were trying to pass to JSON.parse, do you see the date value?A lot of people confuse JSON and JavaScript literal syntax, because JSON is a textual format derived from JavaScript literal syntax. I suspect that’s what’s happening here.