开发者

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.

开发者_JS百科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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜