简体   繁体   中英

JSON vs. XML parsing speed in Flash AS2

All,

I'm working on a Flash AS2 project in which I have a choice of receiving a dataset in either XML or JSON.

The dataset is probably about 100-1,000 rows of data; each row has roughly 50 fields; most values are numeric.

If I use XML, I'll be able to define the XML myself, to make sure it's as compact as possible.

So, I could use something like this:

<rows>
    <row col0="1" col1="2" col2="3" ... col49="50" />
    ...
    <row col0="1" col1="2" col2="3" ... col49="50" />
</rows>

In my initial tests, both the JSON and XML data "weigh" about the same (in kbytes). However, I notice that Flash is able to parse the XML MUCH faster - it takes about 3x as long to parse the JSON. (I'm using the class from http://www.json.org/json.as ).

Based solely on that, I'm inclined to use XML, even though JSON seems to be the much more popular choice these days.

Is the slower JSON parsing typical? Is there a faster class than the one from json.org? Is this because I'm using AS2 instead of AS3 (long story, don't ask...)? Must I be doing something wrong?

Many thanks in advance for any advice or insight.

Cheers, Matt Stuehler

With that small a dataset any differences would probably not be noticeable to the user. But if you are leaning toward XML for performance reasons, let me give you another nudge in that direction by pointing out that using XML lets you use E4X, which is like XPATH for ActionScript. It makes data manipulation easier in code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM