This article mainly introduces how to use JSON in PHP and how to restore json to an array and provides an example analysis. For more information about how to use php to return json data, see the simple example, I just got online and suddenly found an article about json, whic
This article mainly introduces how to use JSON in PHP and how to restore json to an array and provides an example analysis. For more information about how to use php to return json data, see the simple example, I just got online and suddenly found an article about json, whic
Starting with version 5.2, PHP native provides the Json_encode () and Json_decode () functions, which are used for encoding, which is used for decoding.First, Json_encode ()
1234
$arr=array(‘a‘=>1,‘b‘=>2,‘c‘=>3,‘d‘=>4,‘e‘=>5);echojson_encode($arr);?>
Output
1
{"a":1,"b":2,"c":3,"d":4,"e":5}
Let's look at an example of an object conversion:
123456
$obj ->body = ' a
in previous development, it was often encountered to convert a list or array to JSON to the Web front end. For front-end display, but today I encountered a need to pass the JSON array to the background, and afterThe problem of converting the table into list. For this I spent a long time, so I wrote this blog.The first
Before I wrote a simple example of PHP return JSON data, just online, suddenly found an article, also introduced JSON, very detailed, worth reference. The contents are as follows
Starting with version 5.2, PHP native provides the Json_encode () and Json_decode () functions, which are used for encoding, which is used for decoding.
First, Json_encode ()
Copy the Code code as follows:$arr =
First, Json1Json (JavaScript object Notation, JS tag) is a lightweight data interchange format.2.Json Syntax rulesIn the JS language, everything is an object. Therefore, any supported type can be represented by JSON, such as strings, numbers, objects, arrays, and so on. However, objects and arrays are two of the more special and common types:
object is represented as a key-value pair
Data is se
Before I wrote a simple example of PHP return JSON data, just online, suddenly found an article, also introduced JSON, very detailed, worth reference. The contents are as follows
Starting with version 5.2, PHP native provides the Json_encode () and Json_decode () functions, which are used for encoding, which is used for decoding.
First, Json_encode ()
Output
Let's look at an example of an object conversi
The value must be obtained using the obj[xx] method for characters with a key name of numeric or abnormal variables (if there are spaces).
Copy CodeThe code is as follows:
Declaring JSON data$array = Array (' Result ' =>array ("all" = "90 queue", "status" = "success"));$json
We have to write the interface in the daily development work, the output of JSON-formatted text is the production interface must be mastered, now the interface is basically in JSON format data. This article mainly introduces the PHP API interface necessary output JSON format data related to the text through the sample
"). Text (data. CustomerName);});
Requests JSON data to the JSON_1.ASHX address, and after receiving the data, processes the data in the function. The data here is a record that corresponds to a customer instance in which the data exists in k/v form. That is, in the form of a [Object,object] array.{"Unid": 1, "CustomerName": "Song Jiang", "Memo": "Days Kuixing", "other": "Black Three Lang"}
So at
You must use OBJ[XX to obtain a value for a key that is a numeric or characters variable character, such as a space.
Copy Code code as follows:
Declaring JSON data$array = Array (' Result ' =>array ("=>" "90 Queues", "status" => "Success"));$json = Json_encode
Json file is a lightweight data interaction format. The getJSON () method is generally used in jquery to read data. The sample code is as follows. For more information, see, it is expected that your json file is a lightweight data interaction format. GetJSON () is generally used in jquery to read data.
The Code is as follows:
$. GetJSON (url, [data], [callback
Using Newtonsoft.json; VS2013 Introduction: Project->add reference->extensions->json.netnamespace jsonproject{ //json example, // String str = new Type1 (). ToJson (); {"name": "Li Ming", "Age": //type1 obj = type1.parse (str); Create a Type1 object from the JSON string class Type1 {public string name; [Jsonproperty ("Age")]//For age rename public int age;
JSON files are a lightweight form of data interaction. Generally read in jquery using the Getjson () method, the specific sample code is as follows, interested friends can refer to the next ha, hoping to help your JSON file is a lightweight data interchange format. Typically read in jquery using the Getjson () method.Copy CodeThe code is as follows:$.getjson (Url
First you need to download 3 packages, on GitHub Fasterxml, these three core modules are:Streaming ("jackson-core") defines low-level streaming API, and includes json-specific implementations Annotations ("jackson-annotations") contains standard Jackson AnnotationsDatabind ("jackson-databind") implements Data-binding (and object serialization) support on streaming package;It depends both on streaming and annotations packages.
Default format
Copy Code code as follows:
public class MyClass implements serializable{
...}
Serialization:
Copy Code code as follows:
ObjectOutputStream output = new ObjectOutputStream (new FileOutputStream (OutputPath));
Output.writeobject (MyObject);
Deserialization:
Copy Code code as follows:
ObjectInputStream input = new ObjectInputStream (new FileInputStream (InputPath));
Return (MyClass) input.readobject ();
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.