Coder Social home page Coder Social logo

configor's Introduction

👋 Hi there, I'm Nomango

Static Badge Static Badge Static Badge Profile Views

💻 Technologies I use

My Skills

📊 My Stats

configor's People

Contributors

cntrump avatar nomango avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

configor's Issues

as_string报错没有构造函数

非常不错的轮子,但是我在使用中遇到如下问题

using namespace std;
using namespace configor;
json j;
j["123"] = "12345";
string s = j["123"];

vs2017会报错: configor::detail::json_serializer<configor::basic_configconfigor::json_args,configor::basic<_Args>::default_encoding,cofigor::basic_config<_Args>::default_encoding>类没有构造函数

空数组[] 处理不正确。

json.value_.data.vector->push_back(BasicJsonTy());
parse_value(json.value
.data.vector->back());

如果是 "Array":[] 处理不出来

json序列化时格式出错

感谢提供的库,目前遇到这个问题:
对于很小的数使用.dump()序列化后输出

0.005971148862641366^@
-0.00588644005111258^@p
-0.00740774794383903^@o

vs2015编译例程报错

###例程:
#include
#include
#include
#include <configor/json.hpp>

using namespace configor;

// 用户类
struct User
{
int user_id;
std::string user_name;

  JSON_BIND(User, user_id, user_name);

};

int main(int argc, char** argv)
{
std::stringstream s("{"user_id": 10001, "user_name": "John"}");

  // 解析json内容,并反序列化到user对象
  User user;
  s >> json::wrap(user);

  // 序列化user对象并输出
  std::cout << json::wrap(user) << std::endl; // {"user_id":10001,"user_name":"John"}
  return 0;

}

###错误:
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C2679 二进制“=”: 没有找到接受“bool”类型的右操作数的运算符(或没有可接受的转换) jsontest\jsontest\include\configor\configor_parser.hpp 125

template instantiation depth exceeds maximum

使用MinGW编译时,出现如下错误:
F:\jzyou\local-repos\Code\D-Phone\thirtylib\configor\configor_basic.hpp:705: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum)
typename = typename std::enable_if<!is_config<_Ty>::value && detail::is_configor_getable<basic_config, _Ty>::value && !std::is_pointer<_Ty>::value>::type>
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~

编译时,基于c++17

namespace "std" has no member "isdigit"

我在用VS17的build tool和nvcc在Windows10上编译的时候会出现namespace "std" has no member "isdigit"这个error,然后在cpp reference上查到isdigit这个是在里面的,在json_parser.hpp里加上include <cctype>就可以编译通过了,建议在json_parser.hpp里加上这一行

怎么确定解析json失败?

我记得老版解析json的时候可以通过Reader.parse的返回值判断解析是否成功,新版的怎么判断?

About the way to qeury if a key is accessiable

When I ask if there exist a key in the json object, I use:
bool ifhaskey(configor::json js, std::string key) {return !js[key].is_null();}
But it will add null type assoicated with this key to original json. When I just want to ask a key if it is can be accessiable and don't want to set an additional key to mark it null value, which method can be used?

在0.9.11中 编译的时候 报错configor_conversion.hpp:106:123: fatal error: template instantiation depth exceeds maximum of 2048

./include/configor/configor_conversion.hpp:106:123: fatal error: template instantiation depth exceeds maximum of 2048 (use -ftemplate-depth= to increase the maximum)
_ConfTy, _Ty, typename std::enable_if<std::is_void<decltype(config_bind<_Ty>::from_config(std::declval<const _ConfTy&>(), std::declval<_Ty&>()))>::value, void>::type>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
compilation terminated.

json无法操作中文,读取会弹出configor_serialization_error

vs2022 c++14

json j = {
	{"name", "JSON 解析和序列化"},
	{"item", "测试JSON文件加载"}
};

wjson wj = {
	{L"name", L"JSON 解析和序列化"},
	{L"item", L"测试JSON文件加载"}
};

wcout << L"wchar_t\t" << wj << endl;
cout << "char\t" << j << endl;            // configor_serialization_error

处理中文只能用wjson吗

多级json中文出现乱码

struct Config
{
std::string name;
}

Config config;
config.name = XXX;//从MySQL中取值,MySQL设置了字符集为utf8,假定XXX=“**”,此时debug时看到的name就是乱码的

json test;
test["test"] ="中文Test123434";
test["config"] = config;

test.dump()的结果,name显示**,但"中文Test123434"却显示乱码了,请问该如何处理?

结果是以res.set_content(json_result.dump(), "text/plain");形式返回的

赋值double问题

伪代码:
// 1638341381.633359
double time = get_current_time();

// 初始化赋值
json j = {
{"time": time}
};

// 获取值时变成float
j["time"].get()
// 打印 1.63834e+09

是需要额外设置什么参数吗?

一些建议

作者有没有考虑加入追加数组元素功能呢

emm关于wrap?

auto arr = se.get<json::array_type>(); for (unsigned int i = 0; i < arr.size(); i++) { getversion Ver; stringstream ss; ss << arr[i]; ss >> json::wrap(Ver); }
这样可以正常获取arr[i]中的内容并写入Ver,但是
getversion Ver; arr[i].wrap(Ver);
这样获取不到任何内容
所以arr[i].wrap(Ver)作用是啥啊)

C字符串的结束符的解析问题

应该在json.hpp的json_lexer::scan函数内的switch中加入一个case:

case '\0':
result = token_type::end_of_input;
break;

以应对可能从流上读入C字符串末尾的结束符,以免抛出异常:

config deserialization error: unexpected character '\u0000'

类没有构造函数

当我直接引用的时候提示我 “类没有构造函数”错误
“configor::detail::json_lexer<configor::basic_configconfigor::json_args,_SourceEncoding,_TargetEncoding>”: 类没有构造函数
image
这时我引用的代码

请问是什么问题?

序列化包含中文出错

你好,在使用configor时,json包含中文字符串时在序列化时会出错,具体代码如下

#include <iostream>
#include "json.hpp"
int main() {
	using namespace std;
	using namespace configor;
	json j = "宽带连接";
	cout << j.dump() << endl;
	return 0;
}

dump()异常

0x76D7B4B2 处(位于 Project1.exe 中)引发的异常: Microsoft C++ 异常: configor::configor_serialization_error,位于内存位置 0x00DEEA98 处。
0x76D7B4B2 处(位于 Project1.exe 中)引发的异常: Microsoft C++ 异常: [rethrow],位于内存位置 0x00000000 处。
0x76D7B4B2 处(位于 Project1.exe 中)有未经处理的异常: Microsoft C++ 异常: configor::configor_serialization_error,位于内存位置 0x00DEEA98 处。

构造对象中包含数组

我想在构造对象中包含数组,构造函数如下:

            listFileJson=json::object({"filecount",namelist.size(),"fileList",json::array({})});
            for(int i=0;i<namelist.size();++i)
                listFileJson["fileList"].push_back({"filename",namelist[i]});

结果push的时候报错

如何使用C语言原生数组创建json对象?

假如我下面一段代码

json makeJson(int arr[2]) {
        json res = json::array(arr); // 没有这样的重载
        return res;
}

或者有这样一个结构体

struct S {
        int a[5];
        JSON_BIND(S,a); // 绑定a失败
    };

是否有相应的解决方案?

咨询:怎样构造int64的json

请教下如何构建value为int64类型的json。
我如下写法ts会超出范围:
jsonxx::json j = {
{"msgId", “12345”},
{"ts", 1621835751000},
};
std::string strSend = j.dump();

erase函数的用法?

bool server::removeSongsFromPlaylist(configor::json song_list,size_t pid,size_t sid){
    int uid = session_map[sid];
    for(int i = 0;i < song_list;i++){
        auto iter = sobj.config_file["users"][uid]["playlists"][pid].find(song_list[i]);
        sobj.config_file["users"][uid]["playlists"][pid].erase(iter);
    }
    return sobj.updateConfig();
}

我在这个函数中使用了erase函数,但是编译时报错了:

In file included from ./include/configor/configor.hpp:23,
                 from ./include/configor/json.hpp:22,
                 from ./include/storage.cpp:13,
                 from ./include/main.hpp:1,
                 from ./include/main.cpp:1,
                 from ./media_center.cpp:1:
./include/configor/configor_basic.hpp: In instantiation of ‘_IterTy configor::basic_config<_Args>::erase(_IterTy) [with _IterTy = configor::detail::iterator<const configor::basic_config<configor::json_template_args> >; <template-parameter-2-2> = void; _Args = configor::json_template_args]’:
./include/main.cpp:115:68:   required from here
./include/configor/configor_basic.hpp:317:17: error: conversion from ‘iterator<basic_config<[...]>>’ to non-scalar type ‘iterator<basic_config<[...]>>’ requested
  317 |         _IterTy result = end();
      |                 ^~~~~~
./include/configor/configor_basic.hpp:323:20: error: ‘struct configor::detail::iterator<const configor::basic_config<configor::json_template_args> >’ has no member named ‘it_’
  323 |             result.it_.object_iter = value_.data.object->erase(pos.it_.object_iter);
      |             ~~~~~~~^~~
./include/configor/configor_basic.hpp:323:68: error: ‘struct configor::detail::iterator<const configor::basic_config<configor::json_template_args> >’ has no member named ‘it_’
  323 |             result.it_.object_iter = value_.data.object->erase(pos.it_.object_iter);
      |                                                                ~~~~^~~
./include/configor/configor_basic.hpp:329:20: error: ‘struct configor::detail::iterator<const configor::basic_config<configor::json_template_args> >’ has no member named ‘it_’
  329 |             result.it_.array_iter = value_.data.vector->erase(pos.it_.array_iter);
      |             ~~~~~~~^~~
./include/configor/configor_basic.hpp:329:67: error: ‘struct configor::detail::iterator<const configor::basic_config<configor::json_template_args> >’ has no member named ‘it_’
  329 |             result.it_.array_iter = value_.data.vector->erase(pos.it_.array_iter);

这是库的问题吗,如果不是的话,我哪里写错了 qwp

输出时浮点数的格式化有问题导致输出的json文件的数据格式错误

复现代码

using namespace jsonxx;
using namespace std;
int main()
{
    json j;
    j["a_float"] = 1.0f;
    cout << j << endl;
    json p = json::parse("{\"a_float\":1}"); // 上面一行会输出这里的json字符串,然而浮点数输出时没有了小数点
    float f = p["a_float"]; //转换时会出错
    printf("%f",f);
    return 0;
}

个人猜想是在使用std流时没有强制要求输出小数点,因为比如说std::cout<<1.0f<<std::endl会直接输出1而不输出小数点,而使用例如printf("%f", 1.0f)时可以正常输出小数点。
最近比较忙没时间看源码了,作者麻烦修一下吧,或者过几周我再交个PR

不能正确解析integer

std::string的data()内容如下:
{
"code": 0,
"session": "sIMIG9Fe"
}
抛出一下错误:
terminate called after throwing an instance of 'configor::configor_type_error'
what(): config type error: cannot convert type 'string' to type 'integer' (implicitly)

如何用 std::unordered_map 替换 std::map

struct fifo_json_args : json_args
{
template <class _Kty, class _Ty, class... _Args>
using object_type = nlohmann::fifo_map<_Kty, _Ty, _Args...>;
};

// fifo_json 是按插入序排列的
using fifo_json = configor::basic_config<fifo_json_args>;

例程里,用fifom_map替换std::map,使用时编译错误,vs2022

fifo_json j1 = { {"2.name", "2"}, {"1.name", "1"}, {"0.name", "0"} };
fifo_map.hpp(341,19): error C2039: "add_key": 不是 "std::less<std::basic_string<char,std::char_traits,std::allocator>>" 的成员

解析问题

如何解析要求传入iter_begin和iter_end的数据?或如何从char数组中解析?

请问当前有内存泄露的问题吗

我们打算在一个系统中使用这个来频繁读一个配置文件。这里面会建立大量configor::json的临时对象。请问当前的实现的所有数据成员都在栈区吗,如果在堆区,其析构问题是不是已经搞定了?

我看您的文档里面没有提到析构的问题。

使用c++新标准

我注意到README个段代码:

取值的同时判断类型
int n;
bool ret = j["boolean"].get_value(&n); // 若取值成功,ret 为 true

c++在新标准中已经对这种情况做出标准做法:使用std::optional.
修改成标准代码:

取值的同时判断类型
int n;
auto ret = j["boolean"].get_value(); // 若取值成功,ret 为 true
//get_value()应该返回std::optional<int>
if(ret.has_value()) n = ret.value();
else { /*do some thing*/}

如果没有什么特殊需求,都应该使用标准库中的方法.

中文转换乱码的问题

代码如下:
json j;
char * BrokerID = "测试中文";
j["BrokerID"] = BrokerID;
std::string json_str = j.dump();

生成json为:
{"BrokerID":"\uffb2\uffe2\uffca\uffd4\uffd6\uffd0\uffce\uffc4"}

这里生成的unicode编码使用站长工具的unicode转中文工具,转换出来是乱码

VS2017编译例子报错

#include
#include
#include
#include <configor/json.hpp>

using namespace configor;

// 用户类
struct User
{
int user_id;
std::string user_name;

JSON_BIND(User, user_id, user_name);

};

int main(int argc, char** argv)
{
std::stringstream s("{"user_id": 10001, "user_name": "John"}");

// 解析json内容,并反序列化到user对象
User user;
s >> json::wrap(user);

// 序列化user对象并输出
std::cout << configor::json::wrap(user) << std::endl; // {"user_id":10001,"user_name":"John"}


return 0;

}

严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C2064 项不会计算为接受 2 个参数的函数 WindscribeFindNode f:\usr\local\configor-0.9.15\include\configor\configor_basic.hpp 916

严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C2064 项不会计算为接受 3 个参数的函数 WindscribeFindNode f:\usr\local\configor-0.9.15\include\configor\configor_basic.hpp 886

序列化慢

用一个双核A9的板子传一张base46的jpeg图片,大小1M左右,序列化到std::string要花6秒。请问问题主要出在哪里,谢谢。

枚举类型

请问枚举类型该怎么使用JSON_BIND这个宏呢?

例如如下代码

enum TT{
	a,
	b,

//	JSON_BIND(TT,a,b);
};
class Person
{
  public:
	int age;
	string name;
	TT mi;
	std::map<std::string, int> m;
	int tt;

	JSON_BIND(Person,age,name,mi,m,tt);
};``

怎么erase函数还是报错

代码没变,终端输出的东西少了一些,但还有错误

In file included from ./include/configor/configor.hpp:22,
                 from ./include/configor/json.hpp:22,
                 from ./include/storage.cpp:13,
                 from ./include/main.hpp:1,
                 from ./include/main.cpp:1,
                 from ./media_center.cpp:1:
./include/configor/configor_basic.hpp: In instantiation of ‘_IterTy configor::basic_config<_Args>::erase(_IterTy) [with _IterTy = configor::detail::iterator<const configor::basic_config<configor::json_args> >; <template-parameter-2-2> = void; _Args = configor::json_args]’:
./include/main.cpp:115:68:   required from here
./include/configor/configor_basic.hpp:317:17: error: conversion from ‘iterator<basic_config<[...]>>’ to non-scalar type ‘iterator<basic_config<[...]>>’ requested
  317 |         _IterTy result = end();
      |                 ^~~~~~

是一定要用下标吗

(xiaokang00010和leadsoft-ware)的使用者是同一个人,不用介意 ( ̄∇ ̄)

GCC编译示例代码1报错

$ g++ test.cpp -I jsonxx/include/

test.cpp:17:8: error: explicit specialization of ‘template<class _Ty, class _BasicJsonTy, typename std::enable_if<jsonxx::is_basic_json<_BasicJsonTy>::value, int>::type > struct jsonxx::json_bind’ outside its namespace must use a nested-name-specifier [-fpermissive]
17 | struct json_bind {
| ^~~~~~~~~~~~~~~

当json对象是空的时候,序列化到文件再读出来会报错

如题,我序列化了一个空的json对象到文件,然后第二次读取的时候直接报错了
提示

terminate called after throwing an instance of 'configor::configor_deserialization_error'
  what():  config deserialization error: unexpected token 'end_of_input'
Aborted

这是我使用的方式错了还是库原本就有bug

readme示例代码有一处错误

快速上手--使用 std::initializer_list 为 JSON 对象赋值代码

// 第二个对象
json obj2 = ...
{ "object", {
{ "key", "value" },
{ "key2", "value2" },
}, //此处漏了一个 }
};

序列化时key值顺序问题

json对象内部委托std::map实现,key值是有序的,不是插入序,可以留个接口让key值按照插入序来序列化吗?

运行时出错

异常:
terminate called after throwing an instance of 'configor::configor_deserialization_error'
what(): config deserialization error: unexpected token 'end_of_input'
环境:
gcc: 11.1.0
clang: 12.0.1
第一次运行时无错,后来运行就会抛出异常。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.