Json.parse Converting To A String Instead Of Passing Into Array
Yallo, I am at ends as to why notes = JSON.parse(notesString) is converting my array to a string instead of passing my json strings into the array. I tested by checking the typeof
Solution 1:
It is a string because of the outer quotes. If you remove those, your JSON is not valid. You must format it according to the JSON rules. All the keys must be strings, and values can be only primitives, like strings, numbers, booleans, arrays or other JSON objects.
Format your JSON like
[
{
"title": "herp",
"body":"derp"
},
{
"title":"herp",
"body":"derp"
}
]
Here you can see some examples: http://json.org/example.html
Solution 2:
sorry I should have been more specific at the momment it contains
"[{\"title\":\"herp\",\"body\":\"derp\"},{\"title\":\"herp\",\"body\":\"derp\"}]"
That is the JSON expression of a string, which is why you get a string when you parse it.
The string happens to contain a nested set of JSON which is the array you are looking for.
Extract that array from the string and put that in the file.
[{"title":"herp","body":"derp"},{"title":"herp","body":"derp"}]
Post a Comment for "Json.parse Converting To A String Instead Of Passing Into Array"