Git Product home page Git Product logo

x2struct's People

Contributors

xyz347 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  avatar  avatar  avatar  avatar  avatar

x2struct's Issues

如何序列化 QMap

QMap <QString, QList<QString>> x;
x.insert("a", QList<QString>() << "content1" << "content2");

这个 QMap 无法转换成json

not work on windows

error:
x2struct-master/xtypes.h:90:65: error: 'strptime' was not declared in this scope
if (0 != strptime(str.c_str(), "%Y-%m-%d %H:%M:%S", &ttm)) {
^
fix used :
#if defined(__WIN32__)
#ifndef WINDOWS
#define WINDOWS
#endif

in order to fix it :
warn on README that you have to define WINDOWS on windows before importing the library

or

use __WIN32__ instead of WINDOWS

Failed to build with time_t on macOS

time_t is defined as these below in Linux:

time_t 
(in time_t.h) --> typedef __time_t time_t 
(in types.h) --> __STD_TYPE __TIME_T_TYPE __time_t; 
(in typesizes.h) --> #define __TIME_T_TYPE		__SYSCALL_SLONG_TYPE

and finally

#if defined __x86_64__ && defined __ILP32__
# define __SYSCALL_SLONG_TYPE	__SQUAD_TYPE
# define __SYSCALL_ULONG_TYPE	__UQUAD_TYPE
#else
# define __SYSCALL_SLONG_TYPE	__SLONGWORD_TYPE
# define __SYSCALL_ULONG_TYPE	__ULONGWORD_TYPE
#endif

for different platforms.


However, on macOS (at lease in macOS Catalina and 10.14), time_t is defined as long (from the compiler error message)...

Tl; Dr:
Seems that x2struct has a missing convert of type longhttps://github.com/lhy0403/Qv2ray/commit/bcb328e772b50e7896e142450bd89dc9fcf939a0/checks?check_suite_id=379416319#step:6:321

【结构体中调用XTOSTRUCT失败】

你好:
我在声明的结构体中调用了XTOSTRUCT,但是报错了。提示宏定义TOX_ 和 X_STRUCT_L1是未声明的标识符。代码跟进去文件x2struct.hpp,果然没有找到这两个宏定义。宏定义TOS_也没有找到。
这是怎么回事啊?

同样的结构体,希望有值就显示,无值不显示,同样的键,值的类型可能是int类型,或者字符

struct Item 
{
  string label;
  string type;
  string value;
  vector<string> choices;
  XTOSTRUCT(M(label,type, value), O( choices));
};

代码如下

  map<string, Item> members;
  Item test1;
  test1.label = "Canon";
  test1.type = "choice";
  test1.value="Manual";
  test1.choices.resize(2);
  test1.choices[0]="TV";
  test1.choices[1]="AV";
  members["autoexposuremode"] = test1;
  
  Item test2;
  test2.label = "Bracket";
  test2.type = "string";
  test2.value="0";
  members["bracketmode"] = test2;

  string json = x2struct::X::tojson(members); // 结构体转json
  cout << json << endl;

运行结果如下

{
	"autoexposuremode": {
		"label": "Canon",
		"type": "choice",
		"value": "Manual",
		"choices": ["TV", "AV"]
	},
	"bracketmode": {
		"label": "Bracket",
		"type": "string",
		"value": "0",
		"choices": []
	}
}

希望choice,有值就显示,没值不显示

{
	"autoexposuremode": {
		"label": "Canon",
		"type": "choice",
		"value": "Manual",
		"choices": ["TV", "AV"]
	},
	"bracketmode": {
		"label": "Bracket",
		"type": "string",
		"value": "0"
	}
}
  • 还有一种情况,就是value值可能是int类型的,比如日期,不是字符串的,不知道能不能

导入包含 null 的 json 失败

{
    "streamSettings": {
        "headers": null,
        "network": "ws",
        "security": "tls",
        "tlsSettings": {
            "allowInsecure": true,
            "serverName": null
        },
        "wsSettings": {
            "path": "/admin"
        }
    }
}

会出现 SIGABORT 错误

demo编译不过?

example.h(91): error C2664: “bool x2struct::JsonReader::convert(const char *,float &)”: 无法将参数 2 从“char [16]”转换为“std::string &”

std::wstring support

It seems std::wstring is not supported by the x2struct library. Is there any plan to implement that?

Serializing Datetime to JSON

I am using boost::posix_time::ptime for storing datetime in my struct, but I am not able serialize the struct to json.

Deserializing Issue with string type.

struct ConnectionProp{
int connectionId;
std::string connectionName;
double timeout;
XTOSTRUCT(M(connectionId,timeout),O(connectionName));
};

ConnectionProp x;
x2struct::X::loadjson(decodedstr, x, false);

In ConnectionProp object, connectionName property is getting a value of "".

Json is :"{"connectionId":3,"connectionName":"JAY","timeout":3.55566}

QT 5.12引入后报错

project.cpp:15:5: error: use of undeclared identifier 'X_STRUCT_L1_TOX'
x2struct.hpp:780:54: note: expanded from macro 'XTOSTRUCT'

有null的处理失败

{"testVec":["key":null]}

打印:
Parse json string [{"testVec":["key":null]}] fail. :null]}

请问要如何重新实现struct::X::tojson这个函数

非常感谢作者提供这么好的库,因为前端这块要求的json是多了个反斜杠的{"aid":"1","cid":"1","cid_url":"11","time_stamp":"1","status":"1","time_stamp":"1","pic_name":"1","pic_data":"","data":[{"frame_id":"1","time_stamp":"1","alertFlag":"1","headInfo":[{"x":123,"y":123,"width":123,"height":123,"numOfHelmet":"1","color":"1"}]}]},但是这个库转json后是不带反斜杠的,请问如果有重新实现tojson这个函数要在哪里改

QT data type

Hello, I have no problem in using the C + + standard type. Now I have customized the QT qstring to work, but when I want to use QT's qlist, I can't compile it, and the error "error c2039:" struct_to_str ": not a member of" qlist < T > ", I rewrite the conversion function. This is the" template < typename T >

JsonWriter& convert(const char*key, QList&data) {

x2struct_set_key(key);

this->array_begin();

for (size_t i=0; i<data.size(); ++i) {

this->convert("", data[i]);

}

this->array_end();

return *this;

}

I need some help with a complex json

During my program I run a query and I get this result in a string
{ "ok": true, "result": { "message_id": 109, "from": { "id": 3456789, "is_bot": true, "first_name": "ghhdhdsh", "username": "hbdhbhbdh" }, "chat": { "id": 5678, "first_name": "ghj", "last_name": "ghj", "username": "ghj", "type": "private" }, "date": 1606112895, "text": "ddd" } }

So I created some structures
`
struct from {
int id;
bool is_bot;
string first_name;
string username;
XTOSTRUCT( O(id, is_bot,first_name,username));
};

struct chat{
int id;
string first_name;
string last_name;
string username;
string type;
XTOSTRUCT( O(id, first_name,last_name,username,type));
};

struct result: public from,chat{
int message_id;
int date;
string text;
XTOSTRUCT(I(from,chat), O(message_id, date, text));
};

struct retour: public result {
bool ok;
XTOSTRUCT(I(result), O(ok));

};
`

And I want to do something like

if (retour.ok){ cout<<retour.result.chat.username<<" has received the message"; }

How can I do that, I've got some errors.
Thank you

Not able to Serialize Array of Struct

I want to serialize array of struct to json I.E. BestFive_copy Best5Sell[20]; Where BestFive_copy is my struct.I cannot use vector for some reason. Xtostruct is not able to serialize array of struct to json.

About a LICENSE

What is the open source LICENSE for this project?
I want to use it in a project having license GPLv3, I'm not sure what your license is.

Not working with bool datatype

I am trying with bool datatype and i have also passed variable in optional field but xhas method returns 0 and when i evaluate the struct the bool variable contains numeric value..is there any issue with bool datatype?

不支持char

如果结构体里有char,就不支持了,该怎么改

请问,我应该如何解析嵌套的json

我的同事正在使用你的库解析json,他一直坚持你的库无法解析嵌套json,并要求我将嵌套的Object转为String。但我希望数据可以按照json的标准形式进行传输,我不是C++程序员,阅读你的源码有些困难,
所以我希望得到你的帮助。

我坚持的结构:

{
    "errorCode": 0,
    "message": "",
    "data": {
        "timestamp": 1531710826,
        "collections": [
            {
                "temperature": 26.7,
                "mac": "ABCDEF",
                "humidity": 75.1
            },
            {
                "temperature": 25.9,
                "mac": "ABCDE2",
                "humidity": 74.6
            
        ],
        "address": "DEFAB"
    }
}

他所坚持的结构:

{
    "errorCode": 0,
    "message": "",
    "data": "{\"timestamp\": 1531710826,\"collections\": [{\"temperature\": 26.7,\"mac\": \"ABCDEF\","humidity": 75.1},{\"temperature\": 25.9,\"sensorMac\": \"ABCDE2\",\"humidity\": 74.6],\"address\": \"DEFAB\"}"
}

需求:option变量转换到json,没有赋值时不会输出

代码:
struct User
{
int64_t id;
string name;
string mail;
XTOSTRUCT(O(id, name, mail));
};

User user;
user.id = 1;
user.name = "Jack";
string json1 = x2struct::X::tojson(user);
std::cout << json1 << std::endl;

当前输出结果:
{"id":1,"name":"Jack","mail":""}

期望输出结果:
{"id":1,"name":"Jack"}

Conversion of struct to Byte

I am marshalling my struct i.e. converting struct to byte, and sending it to .Net, But when i include XTOSTRUCT(O(Field1,Field2) in my struct size get changed. Due to which, i get wrong structure on .NET side. Do you have any other way apart from declaring XTOSTRUCT field in struct.

嵌套json不知道具体的字段,只做转发用,好像不能解析

data
{
"a": "1",
"extend": {"b": "1", "c": "1", "d": "1", "e": "1", "f": "1", }
}
像这样的 extend 字段,是扩展字段,不知道具体的 字段 有哪些,只是将这个字段做一个转发。
这种情况能不能支持。

我这边用其他 json 库,是直接把 extend 解析成 string 类型

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.