473,378 Members | 1,394 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,378 software developers and data experts.

Can anyone tell me how to use JSON data replied from server?

xhe
I found Jason is a very handy data format for client/server
communication. But I just met a problem as follows:

I want to read the data replied from server in Jason format, the reply
is like this:

[{"firstName":"Alessandro","lastName":"Crugnola","p hone":"+390332730999","email":"al********@sephirot h.it","_explicitType":"tutorials.Person"},
{"firstName":"Patrick","lastName":"Mineault","phon e":"+1234567890","email":"pa*****@5etdemi.com","_e xplicitType":"tutorials.Person"}]

it is generated automatically by amfphp1.9 from an array. I used Ajax
to call a method, and the server code replied an array in the above
json format.

Now comes the problem which I did a huge amount of google search and
can still not find any solution.

HOW CAN I USE THIS REPLY?

Ideally if we can read the reply in array method, it will be
excellent.

I tried this way:

var people= '{"result": '+ reply.responseText +"}";
alert (people.result[1].email)
But it failed.

If we use this to defina a json data

var people =
{"result":
[{"firstName":"Alessandro","lastName":"Crugnola","p hone":"+390332730999","email":"al********@sephirot h.it","_explicitType":"tutorials.Person"},
{"firstName":"Patrick","lastName":"Mineault","phon e":"+1234567890","email":"pa*****@5etdemi.com","_e xplicitType":"tutorials.Person"}]
}
Then I can use
alert ("people is "+ people.result[1].email);
to access the JSON record.

Can anyone tell me how to access the JSON data replied from server?

Thanks very much in advance.

Oct 24 '07 #1
3 2270
On Oct 24, 3:44 pm, xhe <hexuf...@gmail.comwrote:
I found Jason is a very handy data format for client/server
communication. But I just met a problem as follows:

I want to read the data replied from server in Jason format, the reply
is like this:

[{"firstName":"Alessandro","lastName":"Crugnola","p hone":"+390332730999","email":"alessan...@sephirot h.it","_explicitType":"tutorials.Person"},
{"firstName":"Patrick","lastName":"Mineault","phon e":"+1234567890","email":"patr...@5etdemi.com","_e xplicitType":"tutorials.Person"}]

it is generated automatically by amfphp1.9 from an array. I used Ajax
to call a method, and the server code replied an array in the above
json format.

Now comes the problem which I did a huge amount of google search and
can still not find any solution.

HOW CAN I USE THIS REPLY?

Ideally if we can read the reply in array method, it will be
excellent.

I tried this way:

var people= '{"result": '+ reply.responseText +"}";
alert (people.result[1].email)
But it failed.

If we use this to defina a json data

var people =
{"result":
[{"firstName":"Alessandro","lastName":"Crugnola","p hone":"+390332730999","email":"alessan...@sephirot h.it","_explicitType":"tutorials.Person"},
{"firstName":"Patrick","lastName":"Mineault","phon e":"+1234567890","email":"patr...@5etdemi.com","_e xplicitType":"tutorials.Person"}]}

Then I can use
alert ("people is "+ people.result[1].email);
to access the JSON record.

Can anyone tell me how to access the JSON data replied from server?

Thanks very much in advance.
Try this:
var ajaxResponse = eval('(' + response.responseText + ')');
ajaxResponse.firstname.value;
or
ajaxResponse.firstname[0].value;
Hope that help

Oct 24 '07 #2
On Oct 24, 10:31 am, clbr <kalbrun.pa...@gmail.comwrote:
On Oct 24, 3:44 pm, xhe <hexuf...@gmail.comwrote:
I found Jason is a very handy data format for client/server
communication. But I just met a problem as follows:
I want to read the data replied from server in Jason format, the reply
is like this:
[{"firstName":"Alessandro","lastName":"Crugnola","p hone":"+390332730999","email":"alessan...@sephirot h.it","_explicitType":"tutorials.Person"},
{"firstName":"Patrick","lastName":"Mineault","phon e":"+1234567890","email":"patr...@5etdemi.com","_e xplicitType":"tutorials.Person"}]
it is generated automatically by amfphp1.9 from an array. I used Ajax
to call a method, and the server code replied an array in the above
json format.
Now comes the problem which I did a huge amount of google search and
can still not find any solution.
HOW CAN I USE THIS REPLY?
Ideally if we can read the reply in array method, it will be
excellent.
I tried this way:
var people= '{"result": '+ reply.responseText +"}";
alert (people.result[1].email)
But it failed.
If we use this to defina a json data
var people =
{"result":
[{"firstName":"Alessandro","lastName":"Crugnola","p hone":"+390332730999","email":"alessan...@sephirot h.it","_explicitType":"tutorials.Person"},
{"firstName":"Patrick","lastName":"Mineault","phon e":"+1234567890","email":"patr...@5etdemi.com","_e xplicitType":"tutorials.Person"}]}
Then I can use
alert ("people is "+ people.result[1].email);
to access the JSON record.
Can anyone tell me how to access the JSON data replied from server?
Thanks very much in advance.

Try this:
var ajaxResponse = eval('(' + response.responseText + ')');
ajaxResponse.firstname.value;
or
ajaxResponse.firstname[0].value;

Hope that help
That works, however, there are security implications involved should
the source be hijacked by a malicious attacker. Simply running the
JSON through "eval" opens the door to executing arbitrary code; JSON
is merely a data format and has no functions, so take a look at
http://www.json.org/js.html for methods to sanitize your data to
ensure it's safe before running it through "eval".

-David

Oct 24 '07 #3
xhe meinte:

[JSON Reply]
>
HOW CAN I USE THIS REPLY?
Douglas Crockford has written a parser for JSON responses to cope
security issues:

http://www.json.org/js.html
Gregor

--
http://www.gregorkofler.at ::: Landschafts- und Reisefotografie
http://www.licht-blick.at ::: Forum für Multivisionsvorträge
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Oct 24 '07 #4

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

Similar topics

16
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...
20
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... ...
5
by: Dominic Myers | last post by:
In the full and frank knowledge that someone will doubtless refer me to google and probably tell me to wipe my own arse I was wondering if someone could shed some light on the following problem...
1
by: seth | last post by:
Hi: I'm trying to read JSON strings sent from the browser. Here is the scenario: 1. Using YUI tookit 2. sending JSON string from YUI toolkit - using the provided asyncRequest method. **I...
23
by: dhtmlkitchen | last post by:
JSON We all know what it is. In ECMAScript 4, there's a JSON proposal: Object.prototype.toJSONString String.prototype.parseJSON The current proposal, String.prototype.parseJSON, returns...
2
by: vunet | last post by:
When implementing JSON as a form of data exchange between server and client, what security measures do I need to consider? For example, I have XMLHttpRequest returning JSON text from the server and...
9
by: Jon Paal [MSMD] | last post by:
using json like ( {"Records": , "RecordCount":"1" } ) and jquery like: $.ajax({ .... success: function(json, status) {
1
by: bizt | last post by:
Hi, Im currently looking to move into using JSON for AJAX instead of returning from the server a string like the following: 12345{This is a text string{true I prefer objects because I dont...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.