473,320 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

What is wrong with my JSON string?

Hi,

I need some help here. When I try to eval() my AJAX returned JSON
string, I continually get a javascript error "Expected )".

Here's my JSON string:
{"recs": [{"RepKey": "RepKey", "RepID": "RepID", "Type": "Type"},
{"RepKey": "1", "RepID": "000", "Type": "RTRR"},
{"RepKey": "2", "RepID": "0M2", "Type": "RTRR"},
{"RepKey": "3", "RepID": "1DV", "Type": "RTRR"} ]};

My js function simply tries to eval() it:
var jsonStr = eval('(' + str + ')');

When I write str to a div, I get the above JSON string without js
errors. This is driving me crazy. Any help would be hugely
appreciated.

Thanks,
asleep

Feb 6 '07 #1
3 18109
On Feb 5, 5:23 pm, "asleepatdesk" <s...@scoleman.netwrote:
Hi,

I need some help here. When I try to eval() my AJAX returned JSON
string, I continually get a javascript error "Expected )".

Here's my JSON string:
{"recs": [{"RepKey": "RepKey", "RepID": "RepID", "Type": "Type"},
{"RepKey": "1", "RepID": "000", "Type": "RTRR"},
{"RepKey": "2", "RepID": "0M2", "Type": "RTRR"},
{"RepKey": "3", "RepID": "1DV", "Type": "RTRR"} ]};

My js function simply tries to eval() it:
var jsonStr = eval('(' + str + ')');

When I write str to a div, I get the above JSON string without js
errors. This is driving me crazy. Any help would be hugely
appreciated.

Thanks,
asleep
Get rid of the ; at the end.

({asdf:'foo'};) is wrong.
({asdf:'foo'}) is ok.

--
Isaac Z. Schlueter
http://isaacschlueter.com

Feb 6 '07 #2
On Feb 5, 5:53 pm, "Isaac Schlueter" <isaacschlue...@gmail.comwrote:
On Feb 5, 5:23 pm, "asleepatdesk" <s...@scoleman.netwrote:


Hi,
I need some help here. When I try to eval() my AJAX returned JSON
string, I continually get a javascript error "Expected )".
Here's my JSON string:
{"recs": [{"RepKey": "RepKey", "RepID": "RepID", "Type": "Type"},
{"RepKey": "1", "RepID": "000", "Type": "RTRR"},
{"RepKey": "2", "RepID": "0M2", "Type": "RTRR"},
{"RepKey": "3", "RepID": "1DV", "Type": "RTRR"} ]};
My js function simply tries to eval() it:
var jsonStr = eval('(' + str + ')');
When I write str to a div, I get the above JSON string without js
errors. This is driving me crazy. Any help would be hugely
appreciated.
Thanks,
asleep

Get rid of the ; at the end.

({asdf:'foo'};) is wrong.
({asdf:'foo'}) is ok.

--
Isaac Z. Schlueterhttp://isaacschlueter.com- Hide quoted text -

- Show quoted text -
Thanks a lot! That worked. I do have one more question. In the
example that I'm using, the value from the JSON object is retrieved
with a specific reference to the object member name: page['players']
[i].lastName. Is it possible to retrieve the value of the object
member without specifically knowing that it was called "lastName"?
The way my app is being developed, the JSON object is created based on
the the recordset returned from sql. Since the sql field names will
always be different, resulting in different JSON object member names,
I want to retrieve whatever is in page['players'][i].

Thanks again.
asleep

Feb 6 '07 #3
All hail the mighty IN.

for( var i in page.players ) {
for( var j in page.players[i]) {
alert('page.players['+i+'].'+j+' = '+page.players[i][j]);
}
}

IN is also a boolean test.

if( 'asdf' in page.players[i] ) {
alert('the '+i+' player has a asdf and it is '+page.players[i].asdf);
}

--
Isaac Z. Schlueter
http://isaacschlueter.com

Feb 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andy Wawa | last post by:
Hi, on a simple HTML (not an ASP!)-Site I try to connect to a sql server (MS): <html> <title>Test</title> <head> <script language="javascript"> <!-- Function showForm(){
1
by: fusillo | last post by:
i've a problem with the following statement: var eg=eval('('+strjson+')'); making debug with firebug, a firefox extension i got >>> typeof(strjson) "string" >>> inspect(strjson)...
1
by: quantass | last post by:
Im using C#, ASP.NET v1.1. My class contains intrinsic types, ArrayList, and XmlDocument types. Some variables have the value NULL. After usng XmlSerializer and the information on:...
2
by: bylabylamo | last post by:
i have a problem converting a json string that i get from a servlet into a json object using eval function of java script. any one please help me..........
7
by: Andrew Poulos | last post by:
I'm creating a JSON string and passing it to a SCORM 1.2 compliant LMS thus: var tmp = {}; tmp.assess = assessScore; tmp.loc = location; tmp.progress = notes.topics.toString();...
1
by: DR | last post by:
how to determine what language a string is written in? is there any method to take a string and return what language it is in? e.g. english, hindi, spanish, etc.
6
by: pbd22 | last post by:
Hi. I can't seem to get any values from the below string. I have tried myJSONObject.slides, myJSONObject.slides, myJSONObject.slides.1, etc. I can't get it to work. Is it because the NAMES are...
4
Claus Mygind
by: Claus Mygind | last post by:
In my code I am sending a number of records via an ajax post method to the web-server for updating a table. I will parse the query string when it is received on the server side. But I am not sure...
3
by: muddasirmunir | last post by:
I am trying to give the following Icon in my form in vb6. http://www.mediafire.com/?ymzgkgyi50j But , when I put this in my form I got error "Invalid Picutre" What wrong in it? How to add...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.