JSON is used in our PHP development because it often uses AJAX objects to interact with the data between the program and the JS function. Because JS does not know the array in PHP, PHP does not know the array or object in JS. JSON is a good solution to this problem.
Introduction to
1. Convert NSDictionary or NSArray into a JSON string and convert the dictionary or array into a JSON string
1. Convert NSDictionary or NSArray to a JSON string // convert the dictionary or array to a JSON string-(NSData *) toJSON
I put an array serialized in MySQL, and then get it in PHP, sent in JSON format, the interface to accept this data, and then convert the JSON into an array, and finally found that the array product_list key to the corresponding serialized
Because some special character's display effect reason had to change the custom Utf-8 project to the GBK, because uses the AJAX technology, also involves the old problem--the coding transformation. Some form validation needs to return JSON data, PHP's Json_encode function only supports UTF-8 encoding, but only iconv, the effect that needs to be achieved is to convert GBK array to utf-8 function.
The first
① first uses C # in the background to get the menu data in the database, to generate a JSON array containing the menu data items (for some reason not using the order by in SQL), as follows:
View Sourceprint?var menudata1=[ {"OrderID": -10, "text": "Home", "title": "Personal website home page", "url": "Default.aspx?" teacherid=153 "," visible ": true," target ":" _self "}, {" OrderID ": Ten," text ":"
The web-based approach is to use Get_object_vars to convert the class type to an array and then use the foreach traversal to$array = Get_object_vars ($test);$json = ' [{' id ': ' 1 ', ' name ': ' \u5f20\u96ea\u6885 ', ' age ': ', ' subject ': ' \u8ba1\u7b97\u673a\u79d1\u5b66\u4e0e\u6280 \u672f "},{" id ":" 2 "," Name ":" \u5f20\u6c9b\u9716 "," Age ":" + "," Subje
One, array
1. Define one-dimensional array: var s1=new array ();
The code is as follows
Copy Code
s1=[1,2,3,4] or s1[0]=1,s1[1]=2,s1[3]=3,s1[4]=4;
Alert (s1[0]);
The result was 1;
The code is as follows
Copy Code
2, define the two-dimensional group:var s1=new
Data in the client's request body: [{"msg_id": 1, "Msg_status": "Has_read"}, {"msg_id": 2, "Msg_status": "Has_read"}] is a two-dimensional array string$json _data = Json_decode ($GLOBALS [' Http_raw_post_data '], true);In fact, with this sentence can be implemented JSON two-dimensional array string to PHP two-dimension
In the process of interaction between the PHP backend and client data, the JSON data is sometimes formatted in the form of an array, and in a moment the object makes the client developer feel like crashing.Therefore, the front and rear related personnel first to PHP's Json_encode function principle has the necessary understanding is the most important link.The array
This article is mainly to the JS object to the JSON array of simple implementation of the case is introduced, the need for friends can come to the reference, I hope to help youThe code is as follows: function Obj2str (obj) {switch (typeof (obj)) {case ' object ': var ret = []; if (obj instanceof Array) {for (var i = 0, len = obj.length i
var name_value= [{"Name": "Minhang", "Value": 20},{"name": "Pudong New Area", "Value": 30},{"name": "Yangpu", "value": Ten}] var New Array (); for (var in name_value) { list.push (name_value[i].value); } List.sort (function(num1,num2) { return num1-num2; }) var maxcnt= eval (list[list.length-1]);JS gets the JSON obje
The example in this article describes the simple implementation of jquery using $.each to traverse the JSON array. Share to everyone for your reference, specific as follows:
The $ (). each () method of the JQuery object, which can be used to sample any object
The callback function has two parameters:
The first is the index of the member or
A frequently asked question in GoogleGroups is: how to pass a PHP array to Javascript. the answer is to convert the PHP array to JSON. There are several solutions: including third-party PHP class libraries and PHP5JSON extensions (php_json.dll or json. so ). however, the recommended method is to use javascriptHelper of
In JSON, there are two types of structures: objects and arrays.
1. An object begins with "{" (opening parenthesis), and "}" (closing parenthesis) ends. Each "name" is followed by a ":" (a colon), and the ' name/value ' pair is separated by a ', ' (comma). The name is enclosed in quotation marks; If the value is a string, it must be in parentheses, and the numeric type does not need
Son is an exceptionally straightforward data format, and the
The $ (). each () method of the JQuery object, which can be used to sample any objectThe callback function has two parameters:The first is the index of the member or array of the objectExamples of arrays, using element indexes and content$.each ([0,1,2], function (index, content) {Alert ("Item #" + Index + "Its value is:" + content);});The second one is the corresponding variable or contentIf you need to ex
function Xmlstr2js (xmlstr) {var tagnames = Xmlstr.match (/Return Jsonobj}function Deweighttagnames (tagnames) {var len = tagnames.length var _tns = [] for (var i = 0; i Processing XML as an array of JSON objects
Today, as needed, some of the data crawled by the crawler is sorted into a two-dimensional array, then encoded into a JSON string to pass into the database
So the problem is, in PHP, the process is simple, something like this:
$arr [$key 1][$key 2]= $value
In Python, the string cannot be used as a key value, and I don't know about Python, I didn't find the data, and I found this function:
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.