473,836 Members | 1,472 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 18138
On Feb 5, 5:23 pm, "asleepatde sk" <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, "asleepatde sk" <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.pla yers['+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
23518
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
1581
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) {"data":"01\/05\/2006","tipo_selezionato":"premiazione", "lista_orari":,
1
5507
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: http://www.phdcc.com/xml2json.htm I'm having issue fully converitng my class object to a javascript readable string. The XmlSerializer appears to ignore all variables containing NULL and so the final JSON output is incomplete. Also I have a DateTime...
2
3404
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
2504
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(); fScormSetValue("cmi.suspend_data", tmp.toJSONString(), false); alas the LMS complains with this error
1
2171
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
1553
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 numbers? Can you get this to work? Thanks.
4
3305
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 if I need to make each element in each record a unique name/identifier. Right now I was just trying to figure out what the query string looks like when it arrives at the server. I kind of see the errors of my ways, but would like some...
3
7356
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 this in my forms?
0
9825
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10558
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10600
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10257
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.