Giter Club home page Giter Club logo

Comments (3)

Krinkle avatar Krinkle commented on July 27, 2024

From krinklemail on November 13, 2012 17:41:23

Please provide a test case for the test suite (which would fail against the current code).

from jquery-json.

Krinkle avatar Krinkle commented on July 27, 2024

From dzlygin on May 19, 2013 05:34:04

var conf = new Array();
conf['key1'] = {text: 'sometext', posx: 50, posy: 50};
conf['key2'] = {text: 'othertext', posx: 50, posy: 80};

var a = $.toJSON(conf);

this code fails

from jquery-json.

Krinkle avatar Krinkle commented on July 27, 2024

This is not a valid bug for the native JSON.stringify method exhibits the same behaviour and we're just polyfilling that. We can't take feature requests.

Per the ES5 specification, when serialising an Array object:

https://es5.github.io/#x15.12.3

For each value a property [that] has an array index property name. The properties are enumerated in the ascending array index order of their names.

https://es5.github.io/#JA

The representation of arrays includes only the elements between zero and array.length – 1 inclusive. Named properties are excluded from the stringification.

I recommend you do not be add named properties to array objects in your program. You're probably confusing arrays with objects (other programming languages sometimes call them arrays).

var conf = {};
conf.key1 = { text: 'sometext', posx: 50, posy: 50 };
conf.key2 = { text: 'othertext', posx: 50, posy: 80 };

var a = $.toJSON(conf);
// {"key1":{"text":"sometext","posx":50,"posy":50},"key2":{"text":"othertext","posx":50,"posy":80}}

from jquery-json.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.