Example to demonstrate the idea of sending json object as string in OCRepresenation
authorSashi Penta <sashi.kumar.penta@intel.com>
Thu, 9 Oct 2014 17:18:49 +0000 (10:18 -0700)
committerSashi Penta <sashi.kumar.penta@intel.com>
Thu, 9 Oct 2014 20:48:33 +0000 (13:48 -0700)
Change-Id: I73a7c35241a55da856174223e121c3d808ed476f

examples/garageclient.cpp
examples/garageserver.cpp

index 1da8e22..20e88ce 100644 (file)
@@ -135,6 +135,8 @@ void printRepresentation(const OCRepresentation& rep)
         // and has key1 and key2 repsectively
         std::cout << "\treps[0].key1: " << myGarage.m_reps[0].getValue<int>("key1") << std::endl;
         std::cout << "\treps[0].key2: " << myGarage.m_reps[1].getValue<int>("key2") << std::endl;
+
+        std::cout << "\tjson: " << rep.getValue<std::string>("json") << std::endl;
 }
 // callback handler on PUT request
 void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
index 6811e94..343b2a6 100644 (file)
@@ -99,6 +99,12 @@ public:
 
         // storing array of representations
         m_garageRep.setValue("reps", m_reps);
+
+
+        // setting json string
+        std::string json = "{\"num\":10,\"rno\":23.5,\"aoa\":[[1,2],[3]],\"str\":\"john\",\
+\"object\":{\"bl1\":false,\"ar\":[2,3]}, \"objects\":[{\"bl2\":true,\"nl\":null},{\"ar1\":[1,2]}]}";
+        m_garageRep.setValue("json", escapeString(json));
     }
 
     /* Note that this does not need to be a member function: for classes you do not have