JSON file in mbed.
Dependencies: MbedJSONValue SDFileSystem mbed
Fork of City_Game_JSON by
main.cpp@0:b3949bab2aee, 2017-03-15 (annotated)
- Committer:
- AlexVC97
- Date:
- Wed Mar 15 07:55:16 2017 +0000
- Revision:
- 0:b3949bab2aee
- Child:
- 2:e6a095fc2274
JSON in mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AlexVC97 | 0:b3949bab2aee | 1 | #include "mbed.h" |
AlexVC97 | 0:b3949bab2aee | 2 | #include "MbedJSONValue.h" |
AlexVC97 | 0:b3949bab2aee | 3 | #include "picojson.h" |
AlexVC97 | 0:b3949bab2aee | 4 | #include <iostream> |
AlexVC97 | 0:b3949bab2aee | 5 | |
AlexVC97 | 0:b3949bab2aee | 6 | using namespace VivesCityGame; |
AlexVC97 | 0:b3949bab2aee | 7 | |
AlexVC97 | 0:b3949bab2aee | 8 | int main() { |
AlexVC97 | 0:b3949bab2aee | 9 | MbedJSONValue demo; |
AlexVC97 | 0:b3949bab2aee | 10 | |
AlexVC97 | 0:b3949bab2aee | 11 | const char * json = "{\r\n \"gameMode\":\"LocationGame\",\r\n \"gameModeId\":1,\r\n \"version\":\"1.235\",\r\n \"creationDate\":\"11-02-2017\",\r\n \"missions\":[\r\n {\r\n \"missionType\":\"gotoLocation\",\r\n \"missionTypeId\":1,\r\n \"missionMessage\":\"Go to the big roundabout in Oostende.\",\r\n \"deadline\":true,\r\n \"deadlineTime\":30,\r\n \"latitude\":51.215430,\r\n \"longitude\":2.928656,\r\n \"radius\":200\r\n },\r\n {\r\n \"missionType\":\"puzzle\",\r\n \"missionTypeId\":13,\r\n \"missionMessage\":\"Find the key A\",\r\n \"hint\":\"Look in a tree\",\r\n \"deadline\":false,\r\n }\r\n ]\r\n}\r\n"; |
AlexVC97 | 0:b3949bab2aee | 12 | //const char * json = "{\"my_array\": [\"demo_string\", 10], \"my_boolean\": true}"; |
AlexVC97 | 0:b3949bab2aee | 13 | |
AlexVC97 | 0:b3949bab2aee | 14 | //parse the previous string and fill the object demo |
AlexVC97 | 0:b3949bab2aee | 15 | parse(demo, json); |
AlexVC97 | 0:b3949bab2aee | 16 | |
AlexVC97 | 0:b3949bab2aee | 17 | printf(">>> testing if it works properly \r\n"); |
AlexVC97 | 0:b3949bab2aee | 18 | |
AlexVC97 | 0:b3949bab2aee | 19 | std::string game_mode; |
AlexVC97 | 0:b3949bab2aee | 20 | int game_mode_id; |
AlexVC97 | 0:b3949bab2aee | 21 | std::string my_ver; |
AlexVC97 | 0:b3949bab2aee | 22 | std::string creation_date; |
AlexVC97 | 0:b3949bab2aee | 23 | //std::string my_missions; |
AlexVC97 | 0:b3949bab2aee | 24 | //std::string mission_type; |
AlexVC97 | 0:b3949bab2aee | 25 | |
AlexVC97 | 0:b3949bab2aee | 26 | game_mode = demo["gameMode"].get<std::string>(); |
AlexVC97 | 0:b3949bab2aee | 27 | game_mode_id = demo["gameModeId"].get<int>(); |
AlexVC97 | 0:b3949bab2aee | 28 | my_ver = demo["version"].get<std::string>(); |
AlexVC97 | 0:b3949bab2aee | 29 | creation_date = demo["creationDate"].get<std::string>(); |
AlexVC97 | 0:b3949bab2aee | 30 | //my_missions = demo["missions"][0].demo["missionType"].get<std::string>(); |
AlexVC97 | 0:b3949bab2aee | 31 | //mission_type = demo["missionType"].get<std::string>(); |
AlexVC97 | 0:b3949bab2aee | 32 | |
AlexVC97 | 0:b3949bab2aee | 33 | printf("game_mode: %s\r\n", game_mode.c_str()); |
AlexVC97 | 0:b3949bab2aee | 34 | printf("game_mode_id: %d\r\n", game_mode_id); |
AlexVC97 | 0:b3949bab2aee | 35 | printf("my_ver: %s\r\n", my_ver.c_str()); |
AlexVC97 | 0:b3949bab2aee | 36 | printf("creation_date: %s\r\n", creation_date.c_str()); |
AlexVC97 | 0:b3949bab2aee | 37 | //printf("my_missions: %s\r\n", my_missions.c_str()); |
AlexVC97 | 0:b3949bab2aee | 38 | //printf("mission_type: %s\r\n", mission_type.c_str()); |
AlexVC97 | 0:b3949bab2aee | 39 | |
AlexVC97 | 0:b3949bab2aee | 40 | } |