Using ANGULARJS to make a page summary of knowledge Points: String type and JSON convert each other

Source: Internet
Author: User
Tags tojson

The recent week to do a page, the process of production encountered a variety of problems, from which I can see the JS Foundation is not solid enough, ANGULARJS is just the level of entry, now will be the production process encountered in a summary, convenient for later review.

One, string type and JSON convert each other

1, use NG to convert

Angularjs with Fromjson and Tojson two methods for working with conversions between JSON and string types

var json = ' {' name ': ' liSi ', ' Password ': ' 321 '} '; String Type

var jsonarr = ' [{' name ': ' Zhangsan ', ' password ': ' 123 '},{' name ': ' liSi ', ' Password ': ' 321 '}] '; String Type

When you see such data, to get the value of name, password, the first thought must be Json.name, Json.password, Jsonarr[0].name, Jsonarr[1].name, But the actual print will be undefined

It turns out that JSON and Jsonarr are string types, not JSON objects, and you can only convert string types to JSON objects if you want to use the method above to get the values.

The output results are as follows:

Conversely, Angularjs.tojson is converting a JSON object to a string type:

    

2, using JS to convert, please see the article using JS to convert between string and JSON method

Using ANGULARJS to make a page summary of knowledge Points: String type and JSON convert each other

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.