PHP Object goto Array (object to array), JSON to array (JSON to array) method
(1) PHP object to the array method (object to array):
/** * object to array */function Object_to_array ($o
I. Using Gson to convert to JSON formatDependent MAVEN Packages:The key code is as follows:Import Com.google.gson.gson;import com.google.gson.gsonbuilder;import com.google.gson.jsonobject;//....Gson Gson = new Gsonbuilder (). Create ();Gson.tojson ("Hello", System.out);Gson.tojson (123, System.out);System.out.println ();Jsonobject json = new Jsonobject ();Json.ad
":" Before the key is the variable name of the Java object, the colon ":" After the value is a Java object variable values2, arrays and List,json strings are a Jsonarray3,map JSON string is a jsonobject, the colon ":" The precedi
json.js so that IE8 (compatibility mode), IE7 and IE6 can support JSON objects as well as their stringify () and Parse () methods;Can get this JS on Https://github.com/douglascrockford/JSON-js, generally now use json2.js.Ii. conversion of JSON strings to Java objects1. Convert
Net. SF. JSON format date
Similar to other types
Date is before formatting createdate ": {" date ": 4," day ": 2," hours ": 17," Minutes ": 18," month ": 7, "seconds": 34, "Time": 1249377514000, "timezoneoffset":-480, "year": 109}
jsonconfig CFG = new jsonconfig (); cfg. registerjsonvalueprocessor (Java. util. date. class, new jsonvalueprocessor () { private final string format = "yyyy-mm-dd"; Pu
District, Beijing", "age": "23", "name": "JSON"}]
From the results, we can see that both methods can convert java objects into JSON strings, but the converted structure is different.
JSON string -- "java
Examples on the official website
JSON-lib is a Java class package used to convert beans, maps, and XML into JSON and convert JSON back to bean and dynabean.: Http://json-lib.sourceforge
",
Success:function (data) {
$ ("#divShow"). HTML (data);
}
});
This is a simple pass, if you pass multiple arrays, the foreground passes a JSON array of multiple class formats, that is, the collection type. Background processing is cumbersome, such as:[{"Name": "A"},{"name", "B"},{"name", "C"}], you cannot pass, you must use Json.stringify to convert the array
"}, DataType: "JSON", success:function (data) { $ ("#divShow"). HTML (data);} );It is simple to pass if multiple arrays are passed,The foreground passes a JSON array of multiple class formats, that is, the collection type. Background processing is cumbersome, such as:[{" name ":" A "},{" name "," B "},{" name ","
What is JSONJSON (JavaScript Object Notation) is a graceful way to create JavaScript objects. JSON is also a lightweight data interchange format. JSON is very easy for people to read and write, while facilitating machine parsing and generation. JSON is a better solution for exchanging data in Ajax instead of XML.JSON f
This C # wrapper class can be used to convert data in various formats into JSON format, including list conversion to JSON, normal set conversion JSON, DataSet to JSON, DataTable to JSON, DataReader to
Method One:Assembly: System.Web.Extensions;namespaces: System.Web.Script.Serialization;The most important class: JavaScriptSerializerInstantiation ofJavaScriptSerializer js = new JavaScriptSerializer ();Js. Serialize ();//Convert object to JSON string; serial numberJs. Deserialize ();//convert
Today, we use the JSON array and JSON object and JSON type string to transfer and value each other, recording:1.json types of strings converted to JSON objects and values1 var jsonstring = ' {' Bar ': ' Property ', ' Baz ': 3} ';
JSON (JavaScript Object Notation) is a lightweight data exchange format. Easy to read and write. It is also easy to parse and generate machines. It is based on a subset of JavaScript Programming Language, Standard ECMA-262 3rd Edition-December 1999. JSON uses a completely language-independent text format, but it also uses a habit similar to the C language family,
principles, you can use the following functions in the project:
List
public static string Obj2Json
Json to List
public static Object Json2Obj(String json,Type t){ try { System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(t); using (MemoryStream ms = ne
is encoded in json format, which leads to an additional comma when all values are merged into the array. substr () is used for all values () remove the last comma from the function!
Then let's look at the js file.
After we use arr to receive the json Array transmitted to the PHP file
var json = JSON.parse(arr);
JSON
Using Gson to convert a map to JSONGson (also known as Google Gson) is an open-source Java library published by Google, which uses either a serialized Java object as a JSON string or a drag-formatted JSON string as a
For example:
JSON string:var str1 = ' {' name ': ' cxh ', ' sex ': ' Man '} ';JSON object:var str2 = {"Name": "Cxh", "Sex": "Man"};
One, JSON string converted to JSON object
To use the above str1, you must first convert to a
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.