473,499 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what is JSON (short explanation)

184 New Member
hi ...

while the standard HTTP request makes a 'synchronous' call and must wait for the response and makes a page-reload (you always get a new html-page to display) a XMLHttpRequest may be used sync (not typical) and async (the better way) without a page-reload. you may ask for the response with javascript and the response is usually xml- or json-data that you may process with js and update parts of your page through the use of dom-methods that manipulate your document ... so you don't need an entire page-reload because all of that is running in the 'background' ...

kind regards

Hi,
Thank u moderator...
will u please explain me the clear picture of json-Data..
wat does it mean??
and some sites to get basic knowledge in that...

-Hamsa
Aug 29 '07 #1
10 1595
gits
5,390 Recognized Expert Moderator Expert
hi ...

no problem :) ... have a look at the following example that shows you a typical js-object:

Expand|Select|Wrap|Line Numbers
  1. // we create a complex array that contains 3 js
  2. // objects
  3. var js_obj = [
  4.     {val1: 'value1', val2: 'value2'},
  5.     {val1: 'value1', val2: 'value2'},
  6.     {val1: 'value1', val2: 'value2'}
  7. ];
json = javascript object notation and now we get from a, lets say php-json-encoder the following string (as you see it is simply a string that is notated like an native js-obj and only needs to be evaled):

Expand|Select|Wrap|Line Numbers
  1. "[
  2.     {val1: 'value1', val2: 'value2'},
  3.     {val1: 'value1', val2: 'value2'},
  4.     {val1: 'value1', val2: 'value2'}
  5. ]"
  6.  
with that as a responseText you simply may do:

Expand|Select|Wrap|Line Numbers
  1. var data = eval(responseText);
and you get our native js-object in var data ... ok?

kind regards
Aug 29 '07 #2
gits
5,390 Recognized Expert Moderator Expert
hi ... i splitted your JSON-question from the HttpRequest-Thread because i think it may be of interest for more users and so it would be better to find :)

kind regards
Aug 29 '07 #3
gaya3
184 New Member
hi ...

no problem :) ... have a look at the following example that shows you a typical js-object:

Expand|Select|Wrap|Line Numbers
  1. // we create a complex array that contains 3 js
  2. // objects
  3. var js_obj = [
  4.     {val1: 'value1', val2: 'value2'},
  5.     {val1: 'value1', val2: 'value2'},
  6.     {val1: 'value1', val2: 'value2'}
  7. ];
json = javascript object notation and now we get from a, lets say php-json-encoder the following string (as you see it is simply a string that is notated like an native js-obj and only needs to be evaled):

Expand|Select|Wrap|Line Numbers
  1. "[
  2.     {val1: 'value1', val2: 'value2'},
  3.     {val1: 'value1', val2: 'value2'},
  4.     {val1: 'value1', val2: 'value2'}
  5. ]"
  6.  
with that as a responseText you simply may do:

Expand|Select|Wrap|Line Numbers
  1. var data = eval(responseText);
and you get our native js-object in var data ... ok?

kind regards

Hi,
Thank u...I m very new to this...
still it looks greek n latin for me...
ll u please say me still in depth...
will u pl..

-Hamsa
Aug 29 '07 #4
gits
5,390 Recognized Expert Moderator Expert
Hi,
Thank u...I m very new to this...
still it looks greek n latin for me...
ll u please say me still in depth...
will u pl..

-Hamsa
what exactly do you want to know? in the above post you first see a javascript array that has javascript-objects as elements. typical structure of a table ... lets say output of a sql-query. that is what we can handle with javascript ... a javascript-object (i put that to illustrate what we need in js this is what we handle at the client later on -> now we have to get it in any way from the database to the client). but ... the query is done at the server and now we must send its result to the client with a XMLHttpRequest. so the serverside has to encode the result as XML or JSON or whatever ... and when we use JSON-encoding you will send from the server what we see in the second part of the above post. your clientside awaits the responseText and is getting the string i showed you ... we take it, eval it and voila ... we have the js-object we now can handle with javacsript ...

hope this makes it more clear ;)

kind regards
Aug 29 '07 #5
ManWithNoName
88 New Member
Hi, I'm new at JSON too.

I think (I I'm neither a programmer nor a web-dev) you can use JSON strings to send objects and functions (?) back and forth client-side 'n server side with ease. I haven't looked into it so much (not at all in fact ;)) because my current project does not requires it.

While I haven't got around to try it, I am though collecting good tutorials when I see them.

Here are two that I like:

http://www.sergiopereira.com/articles/advjs.html

http://www.dustindiaz.com/json-for-the-masses/

Here is the official site: http://www.json.org/
Aug 29 '07 #6
AMT India
64 New Member
Hi,
Thank u moderator...
will u please explain me the clear picture of json-Data..
wat does it mean??
and some sites to get basic knowledge in that...

-Hamsa

Read this article...very helpfull

http://www.quirksmode.org/blog/archives/2005/12/the_ajax_respon.html
Aug 29 '07 #7
ManWithNoName
88 New Member

Expand|Select|Wrap|Line Numbers
  1. // we create a complex array that contains 3 js
  2. // objects
  3. var js_obj = [
  4.     {val1: 'value1', val2: 'value2'},
  5.     {val1: 'value1', val2: 'value2'},
  6.     {val1: 'value1', val2: 'value2'}
  7. ];
I'd like to see if I have understood this correctly:

"Without JSON" those variables must have been sent as string, like:

Expand|Select|Wrap|Line Numbers
  1. var js_obj = "$a='value1'; $b='value2';]";
// etc.. (or simple stored in a array like structure)

And then in PHP, split, exploded, implode, foreach, destroy, overkill... (or perhaps evaluated in PHP? I would guess that this would create a security issue if the data is user defined, no?)

json = javascript object notation and now we get from a, lets say php-json-encoder the following string (as you see it is simply a string that is notated like an native js-obj and only needs to be evaled):

Expand|Select|Wrap|Line Numbers
  1. "[
  2.     {val1: 'value1', val2: 'value2'},
  3.     {val1: 'value1', val2: 'value2'},
  4.     {val1: 'value1', val2: 'value2'}
  5. ]"
  6.  
with that as a responseText you simply may do:

Expand|Select|Wrap|Line Numbers
  1. var data = eval(responseText);
and you get our native js-object in var data ... ok?
Because of the fact that eval function evaluates anything, anything sent from the server side could be sent simple as var, array and/or functions, e.g. in PHP

$sendBack = "var HelloCode = 'Hello World'; function alarm(str) {alert(str)};

And then in JavaScript one could just run alarm(HelloCode);

So in conclusion, JSON is a method for sending var, objects and functions to the server side? Have I got it right?
Aug 29 '07 #8
gits
5,390 Recognized Expert Moderator Expert
nope ...

i spoke about exactly the other direction ...

1. our client needs simply js data-structures like i showed with the var js_obj (to illustrate how such an obj looks like)

2. we make an ajax call to the server (GET / POST with required params - may be json too but needn't - in case they are we have to encode them at the client to be send correctly as a string and we mustn't eval there but decode/parse -> security reason and operations overhead ... i wouldn't recommend that) ...

3. the service makes a db-call, gets the result, fetches the lines and creates a php-obj that we now json-ENCODE and send back to the client

4. the client evals the json-response and we have a js-obj like in step 1.

kind regards
Aug 29 '07 #9
ManWithNoName
88 New Member
nope ...

i spoke about exactly the other direction ...
... I see that I still have some homework to do then. Well, then, maybe my example could work as a deterrent for others.
Aug 29 '07 #10
gits
5,390 Recognized Expert Moderator Expert
... the conclusion could be ... that json is a better method of sending data to the client then XML would be ... because you will process it with js and it is overhead when sending/parsing XML with js ... since you simply may eval a string to have it js-ready with json ...

kind regards
Aug 29 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

16
2665
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
6807
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... ...
8
10387
by: Douglas Crockford | last post by:
There is a new version of JSON.parse in JavaScript. It is vastly faster and smaller than the previous version. It uses a single call to eval to do the conversion, guarded by a single regexp test to...
2
3727
by: Kevin Newman | last post by:
Hello, I noticed that the JavaScript library for JSON posted on json.org (http://www.json.org/json.js) is modifying Object.prototype (adding a method - toJSONString). I thought this was...
10
2971
by: Frank Millman | last post by:
Hi all I am writing a multi-user accounting/business application, which uses sockets to communicate between server and client. The server contains all the business logic. It has no direct...
1
1712
by: Red Daly | last post by:
Hello group, I have been using JSON for a while and it has made many things a breeze. However, JSON does not natively describe certain things like pointers and custom types. I created a simple...
2
5484
by: kungfumike | last post by:
I am currently having an issue getting json to work. The version of json,js I am using can be found here: http://www.json.org/json.js The file is innclided in standard html <script...
5
10558
by: Marc | last post by:
I'm aware that there are significant differences between VBScript objects and JScript objects but that doesn't mean something like the following should give me such troubles? <%@...
6
2804
by: Lasse Reichstein Nielsen | last post by:
Max <adsl@tiscali.itwrites: Not really. It shows that a particularly naïve implementation of a conversion from XML to JSON doesn't work well. What if the conversion of <e> some
0
7130
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,...
0
7171
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,...
1
6893
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...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4599
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...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
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 ...
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.