Using for in to iterate through the JSON object data, if the name in the data is a number, only valid for positive integer, then output the data as a positive integer, and the others will be output in the same order as defined in the original data.
- Test the data for JSON objects named numbers as follows:
var = { "Json_obj_data": {' title ': ' All ', ' name ': ' All promotions ', ' ID ': ' All '}, "" ": {" title ":" Best_room_rate "," Name ":" Best hostel Rate "," id ":" best_room_rate "}, " ten ": {" title ":" Summer Rate "," name ":" Summer Rate "," id ":" + "}
40,20,10 can be enclosed in double quotes, the output is the same as for (var in json_obj_data) { alert (data ); // 10->20->40 }</script>
- Test the JSON object data with the name string, with the following code:
var json_data = {"3promotion": {"title": "All", "room_promotion_id": "All"}, "2promotion": {" Title ":" Best_room_rate "," roompromotion_id ":" Best_room_rate "}, " 1promotion ": {" title ":" Summer " Rate "," room_promotion_id ":" + "} ; for (var in json_data) { alert (Promotion);//output is in the order defined above}
- For JSON object data tests with names of numbers and strings, the code is as follows:
var json_data = {"3promotion": {"title": "All", "room_promotion_id": "All"}, "2promotion": {" Title ":" Best_room_rate "," roompromotion_id ":" Best_room_rate "}, " 1 ": {" title ":" Summer "," the " _promotion_id ":" "} }; for (var in json_data) { alert (Promotion);//The data first outputs the name as a number and then outputs the name as a string in sequence}
There are two JSON object data tests with a number of names, and others as strings, with the following code:
var json_data = {"3promotion": {"title": "All", "room_promotion_id": "All"}, "2promotion": {" Title ":" Best_room_rate "," roompromotion_id ":" Best_room_rate "}, " 1 ": {" title ":" Summer "," the " _promotion_id ":" "}, " 0 ": {" title ":" Expecial rate "," room_promotion_id ":" $ "} }; for (var in json_data) { alert (Promotion);//Output is 0->1->3promotion-> 2promotion}
The JSON object data that has the name of a number, where there are negative numbers, is treated as a string, and the other is a string, the code is as follows:
var json_data = {"3promotion": {"title": "All", "room_promotion_id": "All" Span style= "color: #000000;" _}, "2promotion": {"title": "Best_room_rate", "roompromotion_id": "Best_room_rate" }, "1": {"title": "Summer", "room_promotion_id": "}, "0": {"title": "Expecial rate", "room_promotion_id": "}, "1": {"title": ' Demo3 ', ' room_promotion_id ': "Demo3" } }; for (var promotion in Json_data) {alert (promotion);//0->1->3promotion->2promotion- >-1}
includes numeric names that are less than 1, and names with negative numbers, and the code is tested as follows:
var json_data = {"3promotion": {"title": "All", "room_promotion_id": "All"}, "2promotion": {" Title ":" Best_room_rate "," roompromotion_id ":" Best_room_rate "}, " 1 ": {" title ":" Summer "," the " _promotion_id ":" "}, " 0.25 ": {" title ":" Expecial rate "," room_promotion_id ":" $ "}, " 1 " : {"title": ' Demo3 ', ' room_promotion_id ': "Demo3"} }; for (var in json_data) { alert (promotion);//1->3promotion->2promotion->0.25- >-1
}