JS implementation of dynamic key value (JSON string considerations: Key and Value are double quotes, the official website is specified in double quotation marks)

Source: Internet
Author: User

1, JSON string considerations: Key and value are double quotation marks, the official website is specified with double quotation marks, as follows:

var mapstr= ' {' A ': ' A ', ' B ': ' B '} ';

var map=json.parse (MAPSTR);

So by stitching strings, JSON parsing gets keyvalue

var str= ' a ';

map[str];//output A

2, also by stitching the string to get keyvalue, using the Eval method to parse the array, note that the arrays

var mapstr= ' [{"A": "A", "B": "B"}] ';

var map=eval (MAPSTR) [0];

map[' A '];//output a

3, there is a more troublesome, is to set the object {Name:key,value:val}, the object is stored multiple times, transform key and Val to get the corresponding data, traversing the name key for the desired value when the Val;

JS implementation of dynamic key value (JSON string considerations: Key and Value are double quotes, the official website is specified in double quotation marks)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.