Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
CasonTsai opened this issue Sep 30, 2020 · 5 comments
Closed

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

CasonTsai opened this issue Sep 30, 2020 · 5 comments

Comments

@CasonTsai
Copy link

非常感谢作者提供这么好的库,因为前端这块要求的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这个函数要在哪里改

@xyz347
Copy link
Owner

xyz347 commented Sep 30, 2020

是所有的双引号都要反斜杠吗?能否给个例子

@CasonTsai
Copy link
Author

这个是x2struct 生成的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"}]}]}

下面这个是asp.net前端那块需要的格式
{\"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\"}]}]}

@CasonTsai
Copy link
Author

我好像找到了,可能要从rapidjson那里改,我试下,如果可以告诉您

@xyz347
Copy link
Owner

xyz347 commented Sep 30, 2020

你试一下调用两次tojson,第一次把结构体转字符串,把转出来的字符串再tojson一次

@CasonTsai
Copy link
Author

两种方法都可以哈哈,谢谢大佬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants