JSON parsing steps, json Parsing
Resolution: The data is stored by the background developers according to the agreed format (hypothetical) and retrieved by the front-end developers according to the format. (Remember: This format is determined by the background developers, and we do not have the right to decide)
The essence of resolution: the process of extracting the desired data in the agreed format.
JSON Parsing System
1. Get the file path first
NSString * jsonPath = [[NSBundlemainBundle] pathForResource: @ "Student" ofType: @ "json"];
2. initialize the NSData object
NSData * data = [NSDatadataWithContentsOfFile: jsonPath];
3. parsing (what type is the outermost layer of data, and what type is used, as shown below)
NSMutableArray * arr = [NSJSONSerializationJSONObjectWithData: dataoptions: NSJSONReadingMutableContainerserror: nil];
The parsing method provided by JSONKit is NSString and NSData. The parsing method is added to the classification, and json format data is parsed into NSArray and NSDictionary. efficiency is second only to the methods provided by the system.
For NSArray and NSDictionary, the classification method is to convert OC objects into JSON strings.
1. Convert the OC array to json format
NSArray * arr = @ [@ "aa", @ "bb", @ "cc", @ "dd", @ "ee"];
Conversion
NSString * jsonStr = [arw.sonstring];
2. Convert the dictionary to JSON format
NSDictionary * dic =@ {@ "name": @ "Frank", @ "gender": @ "man", @ "age": @ "18 "};
NSString * jsonStr = [dicJSONString];
Iii. NSString Parsing
1. Get the file path first
NSString * jsonPath = [[NSBundlemainBundle] pathForResource: @ "Student" ofType: @ "json"];
2. initialize the NSString object
NSString * jsonStr = [NSStringstringWithContentsOfFile: jsonPathencoding: NSUTF8StringEncodingerror: nil];
3. Resolution
NSArray * arr = [jsonStrobjectFromJSONString];
Iv. NSData Parsing
1. Get the file path first
NSString * jsonPath = [[NSBundlemainBundle]
PathForResource: @ "Student" ofType: @ "json"];
2. initialize the NSData object
NSData * data = [NSDatadataWithContentsOfFile: jsonPath];
3. Resolution
NSArray * arr = [dataobjectFromJSONData];
Detailed steps for how to process json in java
Not difficult .. Just a few methods
Zookeeper ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
JSON dependency package:
Json-lib-2.1.jar
Ezmorph-1.0.3.jar
Commons-lang-2.3.jar
Commons-collections-3.2.jar
Commons-beanutils-1.7.0.jar
Commons-logging-1.0.4.jar
Certificate certificate -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1. Use map and list to construct json objects in Java code
Zookeeper ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Map Construction json:
Map map = new HashMap ();
Map. put ("Test 1", "10001 ");
Map. put ("test2", "10002 ");
Map. put ("test3", "10003 ");
JSON json = JSONObject. fromObject (map );
Json is parsed into a Java object:
MorphDynaBean m = (MorphDynaBean) JSONSerializer. toJava (json);/* construct the MorphDynaBean object */
M. get ("test1 ");
M. get ("test2 ");
M. get ("test3 ");
... The remaining full text>
Json parsing set Problems
{
"Status": true,
"Description ":"",
"Value ":[{
"Customer_id": "customer001 ",
"User_id": "user001 ",
"Title": "Test Video 1 ",
"Price": "500 ",
"Purchase_time"
},
{
"Customer_id": "customer001 ",
"User_id": "user001 ",
"Title": "Test video 2 ",
"Price": "500 ",
"Purchase_time"
},
{
"Customer_id": "customer001 ",
"User_id": "user001 ",
"Title": "Test video 3 ",
"Price": "500 ",
"Purchase_time"
}]
}
In the callback function:
Function (json ){
}
Js code:
For (var I = 0i <json. length; I ++ ){
Var status = json [I]. status;
Var value = json [I]. value;
For (var k = 0; k <value. length; k ++ ){
Var customer_id = value [k]. customer_id;
...
}
}
Jquery code:
$. Each (eval (json), function (functions, item ){
Var status = item. status;
Var value = item. value;
$. Each (value, function (values, childItem ){
Var customer_id = childItem. customer_id;
...
})
})... Remaining full text>