473,657 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

having problems parsing JSON

i have an ajax request, where the server is returning:

{"PageDef": {
"pageName": "myname",
"queryName" : "myquerynam e",
"queryCtNam e": "myqueryctn ame"
}};

i have the following code handling it:

var jsontext = response.respon seText;
alert( '(' + jsontext + ')' );
var jsonObj = eval( '(' + jsontext + ')' );
doSomethingWith Obj( jsonObj );

the alert shows the returned content perfectly. but the eval does not
work. i'm getting "missing ) in parenthetical." for a long time i had
"not well-formed", and trying to include "var jsonObj = " in the
return, i would get "syntax error" i think. taking out the '(' an ')'
from the eval statement, i get "invalid label".

i looked around in a lot of places, but could not find anything
definitive on what *exactly* the server's JSON-formatted response
should look like.

can someone help me out?

thanks,

../paul

Apr 22 '06 #1
2 2441
oh - nevermind - the frackin' semicolon was killing me.

Apr 22 '06 #2
VK
pa*****@gmail.c om wrote:
oh - nevermind - the frackin' semicolon was killing me.


Actually you should use the default JSON parser and stringifier
<http://www.json.org/js.html> and contact the producer if something
looks like a per design fault.

I mean of course you are free to write your very own code, but it is
not acommon way (you don't write C+++ from the scratch just because you
had some problem with C++ ;-)

Apr 22 '06 #3

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

Similar topics

16
2686
by: G Matthew J | last post by:
http://htmatters.net/htm/1/2005/07/evaling-JSON.cfm This is more or less in response to Mr Crockford's admonition a few months ago, "fork if you must". Ironically, although in that usenet post he calls what I am suggesting "brittle", his own Javascript JSON parser is not valid JSON, but rather conforms to my proposed variation on JSON!! With an identifier prepended to the front of the JSON block, and function literals as values: see...
20
6845
by: Luke Matuszewski | last post by:
Welcome As suggested i looked into JSON project and was amazed but... What about cyclical data structures - anybody was faced it in some project ? Is there any satisactional recomendation... PS i am ready to use JSON as data/object interchange when using AJAX and my J2EE project - because it is easier to traverse the JavaScript object than its XML representation (so of course may argue).
10
5354
by: Tony | last post by:
I'm wondering if anyone has run any tests to compare the speed of parsing XML vs text in simple lists - such as: <?xml version="1.0" encoding="ISO-8859-1"?> <users> <user>User 1</user> <user>User 2</user> <user>User 3</user> </users>
3
2732
by: sandip desale | last post by:
Dear All, I have a python dictionary file. I want to create a map of that dictionary and want to use the same in my Java Program. Can anybody please tell me how to use the same python dictionary in Java aswell as in Python. Thanks in advance... Regards, Sandip
3
10170
by: Adam | last post by:
I'm trying to retrieve some values from a json object, but instead it's giving me the property name. For example: var json = { "glossary": { "title": "example glossary" } }; console.log(json); alert(json.glossary.title); for (var x in json) { console.log(x); alert(x.title); } This will show me the json object in the console with glossary and title underneath it. When the alert for json.glossary.title fires, it
2
3313
by: ChrisO | last post by:
I've been pretty infatuated with JSON for some time now since "discovering" it a while back. (It's been there all along in JavaScript, but it was just never "noticed" or used by most until recently -- or maybe I should just speak for myself.) The fact that JSON is more elegant goes without saying, yet I can't seem to find a way to use JSON the way I *really* want to use it: to create objects that can be instantated into multiple...
6
5921
by: jackwootton | last post by:
Hello everyone, I understand that XML can be parsed using JavaScript using the XML Document object. However, it is possible to parse XHTML using JavaScript? I currently listen for DOMMutation events, when the events occur I access the node which was inserted or removed (event.target). There is only ever about 5 lines of XHTML nested in the node, however it would be silly for me to parse it manually using methods like hasChildNodes...
11
11214
by: saril.ks | last post by:
Hi The JSON object I am using is as below . this object is returned after an AJAX call {"application" :} In the JS i am using the below code data = ajaxRequest.responseText ;
6
2391
by: Jasper | last post by:
Hi, Maybe this is off-topic, but perhaps you can help. I'm looking for ideas on how to parse a data file. I dont know XML but I know it parses data in text format. I have a structured data file of the general form shown below. I dont have any definition of the data. Basically it looks like it is hierarchical, token/data pairs defined by brackets and square brackets. I would like to parse this out into some sort of data object(s) in...
0
8397
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
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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
8605
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
6167
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
4158
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
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1957
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.