p26001-store-acs-soc-fw-app/util/xpack/example/alias.cpp
2026-09-28 21:33:04 +08:00

27 lines
540 B
C++
Executable file

#include <iostream>
#include "xpack/json.h"
#include "xpack/xml.h"
using namespace std;
struct Test {
long uid;
string name;
XPACK(A(uid, "id xml:xid"), O(name)); // xml use 'xid' and others use 'id'
};
int main() {
Test t;
string json="{\"id\":123, \"name\":\"Pony\"}";
xpack::json::decode(json, t);
cout<<t.uid<<endl;
string xstr = xpack::xml::encode(t, "root");
cout<<xstr<<endl;
Test t1;
xpack::xml::decode(xstr, t1);
cout<<t1.uid<<endl;
return 0;
}