Is parsing JSON faster than parsing XML

前端 未结 11 660
盖世英雄少女心
盖世英雄少女心 2020-12-01 04:51

I\'m creating a sophisticated JavaScript library for working with my company\'s server side framework.

The server side framework encodes its data to a simple XML for

11条回答
  •  有刺的猬
    2020-12-01 05:44

    JSON should be faster since it's JS Object Notation, which means it can be recognized natively by JavaScript. In PHP on the GET side of things, I will often do something like this:

    
    

    For more information on this, see here:

    Why is Everyone Choosing JSON Over XML for jQuery?

    Also...what "extra effort" do you really have to put into "generating" JSON? Surely you can't be saying that you'll be manually building the JSON string? Almost every modern server-side language has libraries that convert native variables into JSON strings. For example, PHP's core json_encode function converts an associative array like this:

    $data = array('test'=>'val', 'foo'=>'bar');
    

    into

    {"test": "val", "foo": "bar"}
    

    Which is simply a JavaScript object (since there are no associative arrays (strictly speaking) in JS).

提交回复
热议问题