int main()
| 6 | |
| 7 | //int main() |
| 8 | int main(int argc, char* argv[]) |
| 9 | { |
| 10 | std::ifstream fin(argv[1]); |
| 11 | if (fin.good()) |
| 12 | { |
| 13 | neb::CJsonObject oJson; |
| 14 | std::stringstream ssContent; |
| 15 | ssContent << fin.rdbuf(); |
| 16 | if (oJson.Parse(ssContent.str())) |
| 17 | { |
| 18 | std::cout << oJson.ToString() << std::endl; |
| 19 | } |
| 20 | else |
| 21 | { |
| 22 | std::cerr << "parse json error" << "\n";// << ssContent.str() << std::endl; |
| 23 | } |
| 24 | fin.close(); |
| 25 | } |
| 26 | int iValue; |
| 27 | double fTimeout; |
| 28 | std::string strValue; |
| 29 | neb::CJsonObject oJson("{\"refresh_interval\":60," |
| 30 | "\"test_float\":[18.0, 10.0, 5.0]," |
| 31 | "\"test_int\":[135355, -1844674407370955161, -935375]," |
| 32 | "\"timeout\":12.5," |
| 33 | "\"dynamic_loading\":[" |
| 34 | "{" |
| 35 | "\"so_path\":\"plugins/User.so\", \"load\":false, \"version\":1," |
| 36 | "\"cmd\":[" |
| 37 | "{\"cmd\":2001, \"class\":\"neb::CmdUserLogin\"}," |
| 38 | "{\"cmd\":2003, \"class\":\"neb::CmdUserLogout\"}" |
| 39 | "]," |
| 40 | "\"module\":[" |
| 41 | "{\"path\":\"im/user/login\", \"class\":\"neb::ModuleLogin\"}," |
| 42 | "{\"path\":\"im/user/logout\", \"class\":\"neb::ModuleLogout\"}" |
| 43 | "]" |
| 44 | "}," |
| 45 | "{" |
| 46 | "\"so_path\":\"plugins/ChatMsg.so\", \"load\":false, \"version\":1," |
| 47 | "\"cmd\":[" |
| 48 | "{\"cmd\":2001, \"class\":\"neb::CmdChat\"}" |
| 49 | "]," |
| 50 | "\"module\":[]" |
| 51 | "}" |
| 52 | "]" |
| 53 | "}"); |
| 54 | std::cout << oJson.ToString() << std::endl; |
| 55 | std::cout << "-------------------------------------------------------------------" << std::endl; |
| 56 | std::cout << oJson["dynamic_loading"][0]["cmd"][1]("class") << std::endl; |
| 57 | oJson["dynamic_loading"][0]["cmd"][0].Get("cmd", iValue); |
| 58 | std::cout << "iValue = " << iValue << std::endl; |
| 59 | oJson["dynamic_loading"][0]["cmd"][0].Replace("cmd", -2001); |
| 60 | oJson["dynamic_loading"][0]["cmd"][0].Get("cmd", iValue); |
| 61 | std::cout << "iValue = " << iValue << std::endl; |
| 62 | oJson.Get("timeout", fTimeout); |
| 63 | std::cout << "fTimeout = " << fTimeout << std::endl; |
| 64 | oJson["dynamic_loading"][0]["module"][0].Get("path", strValue); |
| 65 | std::cout << "strValue = " << strValue << std::endl; |
nothing calls this directly
no test coverage detected