| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
码头工人
10年前发布

简单的C++ JSON库:SimpleJSON

SimpleJSON是一个轻量级的JSON库,用于在C++中从JSON格式导出数据。By taking advantage of templates and operator overloading on the backend, you're able to create and work with JSON objects right away, just as you would expect from a language such as JavaScript. SimpleJSON is packaged as a single C++ Header file "json.hpp".

Upcoming Features

SimpleJSON is still missing some features, which I hope to get done soon!

  • Import JSON from a string.
  • DONE Convert from a JSON object to primitive. Limited to String, Int, Float, and Bool.
  • DONE Allow users to assign to the next available any array index to append to the array:
  JSON array;    array[0] = "Value";    array[1] = 2;    array[2] = true;    array[4] = 1.1; // OK: Element 3 will be initialized to null.

One of the biggests goals for SimpleJSON is for it to be lightweight, and small. Having complicated logic isn't bad, but it bloats the codebase in most cases. I'd like to keep things small rather than put in big features that take a ton of space.

If you run into any bugs, please submit a bug!

Example

More examples can be found in the 'examples' directory. They're the closest thing to an API doc until I have time to write one.

#include "json.hpp"    int main() {    json::JSON obj;    // Create a new Array as a field of an Object.    obj["array"] = json::Array( true, "Two", 3, 4.0 );    // Create a new Object as a field of another Object.    obj["obj"] = json::Object();    // Assign to one of the inner object's fields    obj["obj"]["inner"] = "Inside";      // We don't need to specify the type of the JSON object:    obj["new"]["some"]["deep"]["key"] = "Value";    obj["array2"].append( false, "three" );      std::cout << obj << std::endl;  }

Output:

{    "array" : [true, "Two", 3, 4.000000],    "array2" : [false, "three"],    "new" : {      "some" : {        "deep" : {          "key" : "Value"        }      }    },    "obj" : {      "inner" : "Inside"    }  }

This example can also be written another way:

#include "json.hpp"  #include <iostream>    using json::JSON;    int main() {      JSON obj = {          "array", json::Array( true, "Two", 3, 4.0 ),          "obj", {              "inner", "Inside"          },          "new", {               "some", {                   "deep", {                       "key", "Value"                   }               }           },          "array2", json::Array( false, "three" )      };        std::cout << obj << std::endl;

项目主页:http://www.open-open.com/lib/view/home/1424572684697

 本文由用户 码头工人 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1424572684697.html
JSON开发包 Simplejson