0

I want to reflect a JSON string like the following to a single std::vector<Point>:

[
{
"X": 113.80403039339605,
"Y": 22.652868779963439,
"Z": 113.80403039339605
},
{
"X": 113.80403464036024,
"Y": 22.652860696903234,
"Z": 113.80403464036024
}
]

The std::vector is not a member of a class.

I haven't found this kind of string in the official examples of json_serialization. What should I do?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
cowboylym
  • 13
  • 3
  • Do you consider to use boost::serialization? – shenzhigang Jan 06 '21 at 03:17
  • Thank you for your reply.how ever,I have no problems with json serialization, I want to use the runtime reflection.It makes me high-efficiency to do my job. – cowboylym Jan 06 '21 at 03:22
  • Well, what you should do is do some research, with Google or other search engine, to find some libraries that implement this kind of parsing. Research each library's technical documentation, to determine which one, if any, suit your specific needs, and then proceed and implement your program. That's what you should do. Unfortunately, software library recommendations are off-topic for Stackoverflow, you'll have to do your own research. – Sam Varshavchik Jan 06 '21 at 03:23
  • Well, I think you do have to wrap the `std::vector` into a class, but the example code at least [looks like it knows](https://github.com/rttrorg/rttr/blob/master/src/examples/json_serialization/from_json.cpp#L196-L201) what to do for `std::vector`. – HTNW Jan 06 '21 at 06:42

1 Answers1

0

There are a number of C++ JSON libraries that support mapping JSON data and C++ data structures. Lacking reflection, such libraries rely on traits. Typically the library provides built-in traits specializations for standard library types such as std::vector, and supports custom specializations for user types. See C++ JSON Serialization and How to Convert Vector to JSON Object?

Daniel
  • 728
  • 7
  • 11