You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
841 B

5 months ago
  1. ###使用教程和注意事项
  2. 1.解析
  3. ```c++
  4. auto j3 = json::parse("{ \"happy\": true, \"pi\": 3.141 }");
  5. ```
  6. 2.读
  7. Warning读会抛出异常
  8. use function at() to access the object values rather than operator[]. In case a key does not exist, at throws an exception that you can handle, whereas operator[] exhibits undefined behavior.
  9. 使用方法at去读数值,而不是使用`[]`,如果目标不存在,使用`[]`会造成未定义行为,使用at()会抛出一个异常供处理.
  10. ```c++
  11. j.at("name").get_to(p.name);
  12. j.at("address").get_to(p.address);
  13. j.at("age").get_to(p.age);
  14. or:
  15. s2 = j.at("name").get<std::string>();
  16. 如果通过j["aaa"]["bbb"]去读的话,会自动修改该json文件中的aaa,bbb项{"aaa":{"bbb":null}}
  17. ```
  18. 3.写
  19. ```c++
  20. json["value"] = b1;
  21. ```