I agree it is important for you to know the difference PointedEars. I do
admit that encoding was not necessarily the best word but it's really
just semantics. If you want to get technical, <a
href="http://www.dictionary.com">dictionary.com</a> says that <a
href="http://dictionary.reference.com/search?q=encoding">encoding</a> is
simply "To format (electronic data) according to a standard format"
(notice the use of the word format in there). I think that you are
assuming I was refering to is the <a
href="http://en.wikipedia.org/wiki/Character_encoding">_character
encoding_</a>.
Secondly, my reference to an _array_ was used as a general term. An
array <i>can</i> be a data structure but you really should understand
what an "array of data" is in the context of XML and JSON - can you
imagine what this means in C++ or Java? You can consider an array as a
group of objects/values formatted using either JSON or XML - again ask
dictionary.com what an array is. If someone says you have an array in
JSON then it might look something like this:
{'myArray': [
{'index1': 'value1'},
{'index2': 'value2'},
...]}
while an array in XML might look like this:
<r>
<e a="index1" b="value1" />
<e a="index2" b="value2" />
...
</r>
Essentially both of those are a one dimensional list of objects.
Now that we all understand arrays and encoding we can get on with the
conversation. All that I am saying is that if you have a large _array_
of data (ie a list of, say, customer objects). If you use JSON to
transfer this data from the server to the client then you first have to
call eval(myJSONString) (which is slow) and then loop through the
resulting JavaScript array and build a string or DOM tree of the data
(which can also be slow) that is ready to be put into the web page -
this is not even considering the even slower cases where the data has to
be filtered or sorted. Alternatively, you can return the customer
records to the client as XML in which case all that has to be done is
the XML has to be transformed using an XSLT stylesheet into an HTML
string and then inserted into the document using the innerHTML property.
The XSLT can be used on the client or server (less logic written in
JavaScript :) ) and XSLT has great (fast) support for sorting and
filtering of data.
The important factors here are the length of the array of data you are
dealing with and the target browser. Given that XSLT is quite slow in
Firefox, the question becomes "is the performance hit on Firefox small
enough that the performance in Internet Explorer compensates given the
end user browser demographics".
The one time that JSON is really good is if you are returning a single
record like:
{'car':{
'color':'red',
'make':'Smart',
...}}
and you are going to either insert this into the page DOM or, even
better, you are going to check the color using JavaScript and then do
something else - nothing to do with the UI - based on the color of the
car. In these cases, JSON can be VERY useful.
happy AJAXing.
*** Sent via Developersdex
http://www.developersdex.com ***