S
S
slowkazak2015-09-18 12:43:28
JavaScript
slowkazak, 2015-09-18 12:43:28

Why isn't an array being collected from jquery cookie?

Good afternoon! There is a catch that I can't figure out:
I'm creating an array
from the data I'm collecting for it.

jsonObj={'cid':item_id, 'q':item_count};
//потом в нужный мне момент я пушу все это в массив и все хорошо
items.push(jsonObj);

When the array is there, I create a cookie.
$.cookie('arrcrt', JSON.stringify(items),{ expires: 1});

As a result, the following string is stored in the cookie:

[{'cid':"391299",'q':1},
{'cid':"395367",'q':1},
{'cid':"395690" ,"q":1},
{'cid':"392104",'q':1}]

Back items I get like this:
if($.cookie('arrcrt')!=null)
 {
<b>items = $.parseJSON($.cookie('arrcrt'));</b>
lastid=items.length;
$.each(items, function (key, value) {
//некоторый код который не дает ошибки
});
 }

And that's just when it comes to items = $.parseJSON($.cookie('arrcrt'));

There is an error Uncaught SyntaxError: Unexpected token a
Can anyone tell me what?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pingo, 2015-09-18
@pingo

mb json is not valid, remove its console.log and look in the json validator, for example,
single quotes are extra there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question