missing ] after element list

R

Rahul Mehta

hiii

i have one code
var data =response.cards;
alert(data);
$('#cards_received').html('');

for(var i=0;i<data.length;i++){
var datac=data;
var response = eval(" (" + datac + ") ");
var divcard='<div id="" class="vcard"
onclick="Card.showprofileon_recv_card('+response+');" style="border-
bottom:1px solid white;background-image: url(images/'+data.image
+');">'+data.user_from+'</div>';
$('#cards_received').append(divcard);
}

-------------------------------------------------------------------------------------------------------------------
// getting error here
missing ] after element list
[Break on this error] var response = eval(" (" + datac + ") ");
----------------------------------------------------------------------------
my response
{'success':true,'cards':
[{"message":"","status":"A","user_from":"Rahul1's
Gib","card_type":"Access
Card","image":"wildcard.jpg","cardid":"22","email":"rahul1","gibs":"","msg":"Rahul1's
Gib send you Access Card saying "},
{"message":"sdfdfs","status":"A","user_from":"Rahul2
Rahul2","card_type":"Visiting
Card","image":"friendshipcard.jpg","cardid":"149","email":"rahul2","gibs":"21,1","msg":"Rahul2
Rahul2 send you Visiting Card saying sdfdfs"},
{"message":"sdfdsffd","status":"A","user_from":"rahul
-","card_type":"Visiting
Card","image":"friendshipcard.jpg","cardid":"152","email":"rahul","gibs":"1,14","msg":"rahul
- send you Visiting Card saying sdfdsffd"},
{"message":"","status":"A","user_from":"jane2 -","card_type":"Visiting
Card","image":"friendshipcard.jpg","cardid":"161","email":"jane2","gibs":"15","msg":"jane2
- send you Visiting Card saying "},
{"message":"dsfsdd","status":"A","user_from":"Rishi3
Rishi3","card_type":"Visiting
Card","image":"friendshipcard.jpg","cardid":"162","email":"rishi3","gibs":"39,15","msg":"Rishi3
Rishi3 send you Visiting Card saying dsfsdd"}]}

this
please help why this error is coming

regards
rahul
 
D

David Mark

hiii
Hi!


i have one code

Yes, you sure do. Unfortunately, it is perched on top of other (very
bad) code.
        var data =response.cards;
                        alert(data);
                        $('#cards_received').html('');

                        for(var i=0;i<data.length;i++){
                                var datac=data;
                                var response = eval(" (" + datac + ") ");
                                var divcard='<div id="" class="vcard"
onclick="Card.showprofileon_recv_card('+response+');" style="border-
bottom:1px solid white;background-image: url(images/'+data.image
+');">'+data.user_from+'</div>';
                                $('#cards_received').append(divcard);
                        }

---------------------------------------------------------------------------­----------------------------------------
// getting error here
missing ] after element list
[Break on this error] var response = eval(" (" + datac + ") ");
---------------------------------------------------------------------------­-
my response
{'success':true,'cards':
[{"message":"","status":"A","user_from":"Rahul1's
Gib","card_type":"Access
Card","image":"wildcard.jpg","cardid":"22","email":"rahul1","gibs":"","msg"­:"Rahul1's
Gib send you Access Card saying "},
{"message":"sdfdfs","status":"A","user_from":"Rahul2
Rahul2","card_type":"Visiting
Card","image":"friendshipcard.jpg","cardid":"149","email":"rahul2","gibs":"­21,1","msg":"Rahul2
Rahul2 send you Visiting Card saying sdfdfs"},
{"message":"sdfdsffd","status":"A","user_from":"rahul
-","card_type":"Visiting
Card","image":"friendshipcard.jpg","cardid":"152","email":"rahul","gibs":"1­,14","msg":"rahul
- send you Visiting Card saying sdfdsffd"},
{"message":"","status":"A","user_from":"jane2 -","card_type":"Visiting
Card","image":"friendshipcard.jpg","cardid":"161","email":"jane2","gibs":"1­5","msg":"jane2
- send you Visiting Card saying "},
{"message":"dsfsdd","status":"A","user_from":"Rishi3
Rishi3","card_type":"Visiting
Card","image":"friendshipcard.jpg","cardid":"162","email":"rishi3","gibs":"­39,15","msg":"Rishi3
Rishi3 send you Visiting Card saying dsfsdd"}]}


That hurts my eyes. :(
this
please help why this error is coming

I suggest you get a debugger. Oh and lose jQuery too as it will only
complicate your debugging efforts.

Best of luck. Bye!
 
R

RobG

hiii

i have one code
        var data =response.cards;
                        alert(data);
                        $('#cards_received').html('');

                        for(var i=0;i<data.length;i++){
                                var datac=data;
                                var response = eval(" (" + datac + ") ");
                                var divcard='<div id="" class="vcard"
onclick="Card.showprofileon_recv_card('+response+');" style="border-
bottom:1px solid white;background-image: url(images/'+data.image
+');">'+data.user_from+'</div>';
                                $('#cards_received').append(divcard);
                        }


If you want help, your best bet is to make life as easy as possible
for those reading your post. Format code with indents of 2 or 4 spaces
(not tabs) and wrap at about 70 characters.

It should be possible for readers to copy and paste your posted code,
run it and see the same error as you.

Likely there is an error attempting to eval your JSON.

----------------------------------------------------------------------------
my response
{'success':true,'cards':
[{"message":"","status":"A","user_from":"Rahul1's
Gib","card_type":"Access
Card","image":"wildcard.jpg","cardid":"22","email":"rahul1","gibs":"","msg":"Rahul1's
Gib send you Access Card saying "},

Here's a hint: get your JSON string as a literal and eval it to see if
you get what you expect. If it's not correct, keep cutting it down
until you find out which part is causing you issues.

Tidied up and presented as a string literal (aka JSON):

var obj =
'{' +
' "success": true,' +
' "cards": [' +
' {' +
' "message": "",' +
' "status": "A",' +
' "user_from": "Rahul1\'s Gib",' +
' "card_type": "Access Card",' +
' "image": "wildcard.jpg",' +
' "cardid": "22",' +
' "email": "rahul1",' +
' "gibs": "",' +
' "msg": "Rahul1's Gib send you Access Card saying "' +
' }' +
' ]' +
' }'


I've left the error in there for you to find.

Another suggestion is to keep examples as short as possible while
still illustrating the error. That will often lead you to discover the
error before you post slabs of unformatted, difficult to read code.


[...]
this
please help why this error is coming

Your JSON has embedded quotes, fix them (either using a regular
expression at the client or at the server before sending) before
calling eval.
 
G

Garrett Smith


Please see:
i have one code


Valid javascript source code consists of statements and function
declarations. Invalid code contains SyntaxErrors.

You've posted code using spaces and tabs and the code has wrapped an
line breaks have been inserted, making it syntactically invalid. You did
not state which browsers and versions the error was reported in.

Your code contains references to identifier `$`. I suggest removing that
(whatever it is).

[...]
-------------------------------------------------------------------------------------------------------------------
// getting error here
missing ] after element list
[Break on this error] var response = eval(" (" + datac + ") ");
----------------------------------------------------------------------------

There is an error in eval'ing `data`.
my response
{'success':true,'cards':
[{"message":"","status":"A","user_from":"Rahul1's
A newline in a string literal is a SyntaxError. It cannot be determined
or not this newline was automatically inserted as a result of posting it
or if it was present in your source code. That is why you should have
formatted the lines to about 72 characters.

Have you considered using JSON instead?
<http://json.org>.
 
D

David Mark

i have one code
        var data =response.cards;
                        alert(data);
                        $('#cards_received').html('');
                        for(var i=0;i<data.length;i++){
                                var datac=data;
                                var response = eval(" (" + datac + ") ");
                                var divcard='<div id="" class="vcard"
onclick="Card.showprofileon_recv_card('+response+');" style="border-
bottom:1px solid white;background-image: url(images/'+data.image
+');">'+data.user_from+'</div>';
                                $('#cards_received').append(divcard);
                        }


If you want help, your best bet is to make life as easy as possible
for those reading your post. Format code with indents of 2 or 4 spaces
(not tabs) and wrap at about 70 characters.

It should be possible for readers to copy and paste your posted code,
run it and see the same error as you.


---------------------------------------------------------------------------­----------------------------------------
// getting error here
missing ] after element list
[Break on this error] var response = eval(" (" + datac + ") ");

Likely there is an error attempting to eval your JSON.
---------------------------------------------------------------------------­-
my response
{'success':true,'cards':
[{"message":"","status":"A","user_from":"Rahul1's
Gib","card_type":"Access
Card","image":"wildcard.jpg","cardid":"22","email":"rahul1","gibs":"","msg"­:"Rahul1's
Gib send you Access Card saying "},

Here's a hint: get your JSON string as a literal and eval it to see if
you get what you expect. If it's not correct, keep cutting it down
until you find out which part is causing you issues.


Yes, these types of issues often come down to process of elimination
(though usually with much larger structures than this one).

I considered recommending a binary search pattern, but the posted data
was so messy that it was hard to determine if it would have been
effective (i.e. the missing bracket may have been at the very
beginning or end, making successful bisections impossible).
Tidied up and presented as a string literal (aka JSON):

var obj =
'{' +
'   "success": true,' +
'   "cards": [' +
'       {' +
'               "message": "",' +
'               "status": "A",' +
'               "user_from": "Rahul1\'s Gib",' +
'               "card_type": "Access Card",' +
'               "image": "wildcard.jpg",' +
'               "cardid": "22",' +
'               "email": "rahul1",' +
'               "gibs": "",' +
'               "msg": "Rahul1's Gib send you Access Card saying "' +
'       }' +
'   ]' +
' }'

Looks much smaller now. :)
I've left the error in there for you to find.

Turns out a binary pare-down would be effective as there is no missing
bracket. But ISTM that a decent debugger (or editor) would point out
the offensive line (if not the exact character).
Another suggestion is to keep examples as short as possible while
still illustrating the error. That will often lead you to discover the
error before you post slabs of unformatted, difficult to read code.

[...]


this
please help why this error is coming

Your JSON has embedded quotes, fix them (either using a regular
expression at the client or at the server before sending) before
calling eval.

Aw, you spoiled his bug hunt. :)
 
R

Ry Nohryb

(...)
Your JSON has embedded quotes, fix them (either using a regular
expression at the client or at the server before sending) before
calling eval.

That text is not valid JSON but not for the reason you state (since
when a JSON text can't contain (unescaped) quotes ? (*)), but that's
not (not being JSON) a reason for it to throw when eval'ed, because as
far as we can see -in what he's posted- it looks like a 100% valid
javascript object literal (not JSON)... unless there's a CR left in it
somewhere -which we can hardly distinguish in his post-.

(*)One thing is a JSON text, and another -different- thing is a string
literal representing an object literal text or a JSON text, which is
what you've posted, and would need to have the quotes escaped. But if
the text he is trying to eval were exactly what he's posted (and
without any CRs), it would eval OK, without any errors, because it's a
*perfectly*valid* javascript object literal (although not valid JSON).
 
R

Ry Nohryb

(...) because it's a
*perfectly*valid* javascript object literal (although not valid JSON).

IOW:

b64="eydzdWNjZXNzJzp0cnVlLCdjYXJkcyc6IFt7Im1lc3NhZ2UiOiIiLCJzdGF0dXMiOiJBIiwidXNlcl9mcm9tIjoiUmFodWwxJ3MgR2liIiwiY2FyZF90eXBlIjoiQWNjZXNzIENhcmQiLCJpbWFnZSI6IndpbGRjYXJkLmpwZyIsImNhcmRpZCI6IjIyIiwiZW1haWwiOiJyYWh1bDEiLCJnaWJzIjoiIiwibXNnIiA6IlJhaHVsMSdzIEdpYiBzZW5kIHlvdSBBY2Nlc3MgQ2FyZCBzYXlpbmcgIn0sIHsibWVzc2FnZSI6InNkZmRmcyIsInN0YXR1cyI6IkEiLCJ1c2VyX2Zyb20iOiJSYWh1bDIgUmFodWwyIiwiY2FyZF90eXBlIjoiVmlzaXRpbmcgQ2FyZCIsImltYWdlIjoiZnJpZW5kc2hpcGNhcmQuanBnIiwiY2FyZGlkIjoiMTQ5IiwiZW1haWwiOiJyYWh1bDIiLCJnaWJzIjoiIDIxLDEiLCJtc2ciOiJSYWh1bDIgUmFodWwyIHNlbmQgeW91IFZpc2l0aW5nIENhcmQgc2F5aW5nIHNkZmRmcyJ9LCB7Im1lc3NhZ2UiOiJzZGZkc2ZmZCIsInN0YXR1cyI6IkEiLCJ1c2VyX2Zyb20iOiJyYWh1bCAtIiwiY2FyZF90eXBlIjoiVmlzaXRpbmcgQ2FyZCIsImltYWdlIjoiZnJpZW5kc2hpcGNhcmQuanBnIiwiY2FyZGlkIjoiMTUyIiwiZW1haWwiOiJyYWh1bCIsImdpYnMiOiIxICwxNCIsIm1zZyI6InJhaHVsIC0gc2VuZCB5b3UgVmlzaXRpbmcgQ2FyZCBzYXlpbmcgc2RmZHNmZmQifSwgeyJtZXNzYWdlIjoiIiwic3RhdHVzIjoiQSIsInVzZXJfZnJvbSI6ImphbmUyIC0iLCJjYXJkX3R5cGUiOiJWaXNpdGluZyBDYXJkIiwiaW1hZ2UiOiJmcmllbmRzaGlwY2FyZC5qcGciLCJjYXJkaWQiOiIxNjEiLCJlbWFpbCI6ImphbmUyIiwiZ2licyI6IjEgNSIsIm1zZyI6ImphbmUyIC0gc2VuZCB5b3UgVmlzaXRpbmcgQ2FyZCBzYXlpbmcgIn0sIHsibWVzc2FnZSI6ImRzZnNkZCIsInN0YXR1cyI6IkEiLCJ1c2VyX2Zyb20iOiJSaXNoaTMgUmlzaGkzIiwiY2FyZF90eXBlIjoiVmlzaXRpbmcgQ2FyZCIsImltYWdlIjoiZnJpZW5kc2hpcGNhcmQuanBnIiwiY2FyZGlkIjoiMTYyIiwiZW1haWwiOiJyaXNoaTMiLCJnaWJzIjoiIDM5LDE1IiwibXNnIjoiUmlzaGkzIFJpc2hpMyBzZW5kIHlvdSBWaXNpdGluZyBDYXJkIHNheWluZyBkc2ZzZGQifV19"

atob(b64)
--> "{'success':true,'cards':
[{"message":"","status":"A","user_from":"Rahul1's
Gib","card_type":"Access
Card","image":"wildcard.jpg","cardid":"22","email":"rahul1","gibs":"","msg":"Rahul1's
Gib send you Access Card saying "},
{"message":"sdfdfs","status":"A","user_from":"Rahul2
Rahul2","card_type":"Visiting
Card","image":"friendshipcard.jpg","cardid":"149","email":"rahul2","gibs":"
21,1","msg":"Rahul2 Rahul2 send you Visiting Card saying sdfdfs"},
{"message":"sdfdsffd","status":"A","user_from":"rahul
-","card_type":"Visiting
Card","image":"friendshipcard.jpg","cardid":"152","email":"rahul","gibs":"1,
14","msg":"rahul - send you Visiting Card saying sdfdsffd"},
{"message":"","status":"A","user_from":"jane2 -","card_type":"Visiting
Card","image":"friendshipcard.jpg","cardid":"161","email":"jane2","gibs":"1
5","msg":"jane2 - send you Visiting Card saying "},
{"message":"dsfsdd","status":"A","user_from":"Rishi3
Rishi3","card_type":"Visiting
Card","image":"friendshipcard.jpg","cardid":"162","email":"rishi3","gibs":"
39,15","msg":"Rishi3 Rishi3 send you Visiting Card saying dsfsdd"}]}"

eval("("+ atob(b64)+ ")")
--> Object
success: true
cards: Array[5]
0: Object
1: Object
2: Object
3: Object
4: Object
length: 5
 
D

Dr J R Stockton

In comp.lang.javascript message <a02b9982-8561-4cda-9b06-c050357be933@v3
5g2000prn.googlegroups.com>, Sun, 22 Aug 2010 23:35:41, RobG
If you want help, your best bet is to make life as easy as possible
for those reading your post.
Yes.


Format code with indents of 2 or 4 spaces

Nothing wring with 3, AFAIK.

(not tabs) and wrap at about 70 characters.

CAREFUL. It MUST NOT be wrapped by the posting agent, which will break
lines in inappropriate places. Better IMHO not to use the word "wrap",
and say something like "use lines of not more than about 72 characters".
 
G

Garrett Smith

CAREFUL. It MUST NOT be wrapped by the posting agent, which will break
lines in inappropriate places.
Yes, and that looks like what happened in the post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top