In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "understanding JSON objects and arrays". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Introduction to JSON
JSON (JavaScript Object Notation) is a lightweight data exchange format. It is based on a subset of ECMAScript. JSON uses a completely language-independent text format, but also uses conventions similar to the C language family (including C, C++, C #, Java, JavaScript, Perl, Python, and so on). These features make JSON an ideal data exchange language. It is easy for people to read and write, and it is also easy to be parsed and generated by machines (generally used to increase the network transmission rate).
Json is an extremely easy-to-understand data format, and the rules for json are only as follows:
1) the juxtaposed data is separated by a comma (",").
2) the mapping is indicated by a colon (":").
3) A collection (array) of juxtaposed data is represented by square brackets ("[]").
4) the mapped set (object) is represented by curly braces ("{}").
JSON has two structured arrays and objects: arrays represent collections of ordered data, and objects represent collections of unordered data.
Look at the following example:
$arr = array); $arr1 = array ('a'= > 'aaa','b' = > 2222); $arr2 = array (' a'= > 'aaa','other' = > array (' bbb',1111)); echo json_encode ($arr); / / [111l, "aaa", "bbb"] echo json_encode ($arr1); / / {"a": "aaa", "b": 222} echo json_encode ($arr2) / {"a": "aaa", "other": ["bbb", 1111]}
As you can see from above: because javascript does not support associative arrays, json_encode () only converts indexed arrays (indexed array) to array format and associative arrays (associative array) to object format.
Notes on PHP's support for json:
Json_encode only supports UTF-8-encoded data
Json_decode always reflects only one PHP object, and an array can be returned with the second parameter true:
Json ='{"a": "aaa", "other": ["bbb", 1111]}'; print_r (json_decode ($json)); print_r (json_decode ($json, true)); "understanding of JSON objects and arrays" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.