# SimpleJSON
Simple C++ JSON library
## License
Do what the fuck you want public license
## About
SimpleJSON is a lightweight JSON library for exporting data in JSON format from C++. 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 a single C++ Header file, "json.hpp". Feel free to download this file on its own, and include it in your project. No other requirements!
#### Platforms
SimpleJSON should work on any platform; it's only requirement is a C++11 compatible compiler, as it make heavy use of the C++11 move semantics, and variadic templates. The tests are tailored for linux, but could be ported to any platform with python support and a C++11 compiler.
## API
You can find the API [over here](API.md). For now it's just a Markdown file with C++ syntax highlighting, but it's better than nothing!
## Upcoming Features
SimpleJSON is still missing some features, which I hope to get done soon!
* Write more test cases to cover all major components( mostly parsing )
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, or see that I'm missing a featuer, please submit an issue through GitHub and I'll respond as soon as I can!
## Example
More examples can be found in the 'examples' directory. Check out [the API](API.md) for a full list of functions.
```cpp
#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" );
// We can also parse a string into a JSON object:
obj["parsed"] = JSON::Load( "[ { \"Key\" : \"Value\" }, false ]" );
std::cout << obj << std::endl;
}
```
Output:
```
{
"array" : [true, "Two", 3, 4.000000],
"array2" : [false, "three"],
"new" : {
"some" : {
"deep" : {
"key" : "Value"
}
}
},
"obj" : {
"inner" : "Inside"
},
"parsed" : [{
"Key" : "Value"
}, false]
}
```
This example can also be written another way:
```cpp
#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;
```
Sadly, we don't have access to the : character in C++, so we can't use that to seperate key-value pairs, but by using commas, we can achieve a very similar effect. The other point you might notice, is that we have to explictly create arrays. This is a limitation of C++'s operator overloading rules, so we can't use the [] operator to define the array :( I'm looking into ways to make this smoother.
没有合适的资源?快使用搜索试试~ 我知道了~
Simple C++ JSON library.zip
共26个文件
json:13个
cpp:7个
md:2个
需积分: 5 0 下载量 6 浏览量
2024-01-05
14:46:36
上传
评论
收藏 13KB ZIP 举报
温馨提示
Simple C++ JSON library
资源推荐
资源详情
资源评论
收起资源包目录
Simple C++ JSON library.zip (26个子文件)
sss
json.hpp 22KB
examples
iter_example.cpp 1KB
array_example.cpp 423B
load_example.cpp 723B
init_example.cpp 339B
json_example.cpp 2KB
prim_example.cpp 407B
API.md 4KB
test
cases
test9.json 8B
test5.json 13B
test8.json 3B
test1.json 5B
test2.json 5B
test11.json 343B
test12.json 3B
test6.json 3B
test3.json 4B
test4.json 6B
test10.json 32B
test13.json 8B
test7.json 24B
run.py 718B
tester.cpp 810B
.gitignore 267B
README.md 3KB
build.sh 782B
共 26 条
- 1
资源评论
Lei宝啊
- 粉丝: 2051
- 资源: 1330
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功