Git Product home page Git Product logo

Comments (5)

qicosmos avatar qicosmos commented on June 2, 2024

这样不是更简单么?

struct taget_t {
  int version;
  Info info;
};
REFLECTION(taget_t, version, info);

std::string str = R"({"version":1, "info": {"idx": 1, "val": "abc"}})";

taget_t t{};
iguana::from_json(str, t);

auto id = t.info.idx;

from iguana.

qicosmos avatar qicosmos commented on June 2, 2024

如果用parse方式的话就没法转成结构体了,就要用jvalue了,参考https://github.com/qicosmos/iguana/blob/master/test/test.cpp#L198

from iguana.

DoIthd avatar DoIthd commented on June 2, 2024

这样不是更简单么?

struct taget_t {
  int version;
  Info info;
};
REFLECTION(taget_t, version, info);

std::string str = R"({"version":1, "info": {"idx": 1, "val": "abc"}})";

taget_t t{};
iguana::from_json(str, t);

auto id = t.info.idx;

感谢大佬回复,应用场景是这样的,对于Info, 不同版本可能会不一样,要根据version选择对应的结构体。

from iguana.

qicosmos avatar qicosmos commented on June 2, 2024

后面会支持部分解析,应该能满足你这个需求。

from iguana.

bbbgan avatar bbbgan commented on June 2, 2024

抱歉,回复晚了,不同的info虽然有不一样的版本,但是只要不是冲突的就可以的,比如:

// 注册元信息
struct Info {
int idx;
std::string val;
std::string newval;
};
REFLECTION(Info, idx, val);
struct taget_t {
  int version;
  Info info;
};
REFLECTION(taget_t, version, info);
// 版本1
std::string str1 = R"({"version":1, "info": {"idx": 1, "val": "abc"}})";
taget_t t{};
iguana::from_json(st1, t);
// 版本2
std::string str2 = R"({"version":2, "info": {"idx": 1, "newval": "abc"}})";
taget_t t{};
iguana::from_json(str2, t);

之后会考虑冲突了应该如何处理,应该需要部分解析,或者延迟解析解决。

from iguana.

Related Issues (20)

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.