JSON file in mbed.

Dependencies:   MbedJSONValue SDFileSystem mbed

Fork of City_Game_JSON by Alex Vancoillie

main.cpp

Committer:
AlexVC97
Date:
2017-03-15
Revision:
0:b3949bab2aee
Child:
2:e6a095fc2274

File content as of revision 0:b3949bab2aee:

#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());
    
}