JSON file in mbed.
Dependencies: MbedJSONValue mbed SDFileSystem
Diff: main.cpp
- Revision:
- 0:b3949bab2aee
- Child:
- 2:e6a095fc2274
diff -r 000000000000 -r b3949bab2aee main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Mar 15 07:55:16 2017 +0000 @@ -0,0 +1,40 @@ +#include "mbed.h" +#include "MbedJSONValue.h" +#include "picojson.h" +#include <iostream> + +using namespace VivesCityGame; + +int main() { + MbedJSONValue demo; + + 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"; + //const char * json = "{\"my_array\": [\"demo_string\", 10], \"my_boolean\": true}"; + + //parse the previous string and fill the object demo + parse(demo, json); + + printf(">>> testing if it works properly \r\n"); + + std::string game_mode; + int game_mode_id; + std::string my_ver; + std::string creation_date; + //std::string my_missions; + //std::string mission_type; + + game_mode = demo["gameMode"].get<std::string>(); + game_mode_id = demo["gameModeId"].get<int>(); + my_ver = demo["version"].get<std::string>(); + creation_date = demo["creationDate"].get<std::string>(); + //my_missions = demo["missions"][0].demo["missionType"].get<std::string>(); + //mission_type = demo["missionType"].get<std::string>(); + + printf("game_mode: %s\r\n", game_mode.c_str()); + printf("game_mode_id: %d\r\n", game_mode_id); + printf("my_ver: %s\r\n", my_ver.c_str()); + printf("creation_date: %s\r\n", creation_date.c_str()); + //printf("my_missions: %s\r\n", my_missions.c_str()); + //printf("mission_type: %s\r\n", mission_type.c_str()); + +} \ No newline at end of file