Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Eric

Eric Avatar



1,442


November 2005
www.crockford.com/JSON/

Basically a form of storing information in an javascript object like manner. It has a few more specifics though, mostly so that other languages besides javascript can read and write it easily.

It is starting to be used for AJAX, which seems interesting. A switch from the pure HTML or XML that people are used to.


Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Well, I'm still not quite sure on what exactly it is. Probably my lack of knowledge in the AJAX category, or because I'm not one of those people who knows lots of terms.

Eric

Eric Avatar



1,442


November 2005
cddude229 said:
Well, I'm still not quite sure on what exactly it is. Probably my lack of knowledge in the AJAX category, or because I'm not one of those people who knows lots of terms.
Check the link at the top. Not really much to do with AJAX, but its used with it sometimes.

The idea of it is a way to store information in a text format. The format is most similar to javascript objects. Main difference is that there are certain extra requirements, like properties have to have quotes around them, while this is not true in javascript. However javascript will read it properly either way.

Imagine it like XML, except a completely different format. It can be used to store tons of information.

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
I had read it, but It hadn't made sense. :P But how you said it did. So basically, it just returns an object containing the information?

Also, is it basically just the same functionality as using an object?

Eric

Eric Avatar



1,442


November 2005
cddude229 said:
I had read it, but It hadn't made sense. :P But how you said it did. So basically, it just returns an object containing the information?

Also, is it basically just the same functionality as using an object?
An object in string form though.

Like:
{
"books": {
"authors": ["Monkey", "Giraffe"],
"titles": ["Insects", "Grass"]
}
};

That would be kept in string form.

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Ah, makes sense. I don't have much knowledge in the object category, so this is most likely why it is confusing me. :P

One question, would Like.books.authors[0] be correct to get "Monkey"?

Eric

Eric Avatar



1,442


November 2005
cddude229 said:
Ah, makes sense. I don't have much knowledge in the object category, so this is most likely why it is confusing me. :P

One question, would Like.books.authors[0] be correct to get "Monkey"?
Well technically you'd have to eval the string holding the notation first. Or if you're using another language you'd have to convert.

But in JS, yeah, that would work.

crazynarutard

crazynarutard Avatar

*****
Senior Studio Member

1,470


August 2005
rawr

The link you provided is not enough and Google gave me crap. Got any more links?

Eric

Eric Avatar



1,442


November 2005

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Gotta love Wikipedia. I read that article, and it explained a little more. Though I still don't see the real purpose behind using JSON as opposed to a normal object. What exactly would be the main advantage when using it? Is it faster? More professional?

Eric

Eric Avatar



1,442


November 2005
cddude229 said:
Gotta love Wikipedia. I read that article, and it explained a little more. Though I still don't see the real purpose behind using JSON as opposed to a normal object. What exactly would be the main advantage when using it? Is it faster? More professional?
JSON is for storing information in a text format. As of now you are thinking only in terms of javascript. But imagine that PHP could easily echo out something like JSON. Like I said, it is like XML. Simply a way of storing information. The way that it ties into javascript besides that it takes its hash table set up, is that it is often used with AJAX. You see you send the request, and the server-side language will return a piece of JSON. Since you are using responseText, the object will be in string format, rather then objects which are just what they are.

You can use javascript's eval function to turn this string object into a realy object. However that is only if you are using it with javascript, which is not required.

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Oh, ok. That actually makes a hell of a lot more sense. :P

But how is using this a better method then XML or just returning a text page?

(Sorry for the annoying questions. :P)

Eric

Eric Avatar



1,442


November 2005
cddude229 said:
Oh, ok. That actually makes a hell of a lot more sense. :P

But how is using this a better method then XML or just returning a text page?

(Sorry for the annoying questions. :P)
The main reason is that XML is overly wordy with both opening and closing tags, while in JSON you just use a comma to indicate the end (or close the object).

Another reason is that with AJAX, you don't have to run through the XML using DOM, you can just eval the piece of JSON, and have a normal object.

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
That makes sense. Plus, then its just easier to use things like what I demonstrated above (Like.books.authors[0], etc.). I'll actually take a look into this. Thanks for the info Eric. :D

newBookmarkLockedFalling