I have a json string which I want to convert to a thrift object.
The thrift definition is
struct Person {
1: optional string name;
}
My code is
#include <thrift/TBase.h>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/protocol/TJSONProtocol.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/transport/TTransportUtils.h>
#include <cstring>
#include "Person_types.h"
int main() {
std::string s = R"({"name": "alice"})";
auto transport = std::make_shared<apache::thrift::transport::TMemoryBuffer>((uint8_t *)s.data(), s.length());
auto protocol_factory = std::make_shared<apache::thrift::protocol::TJSONProtocolFactory>();
auto protocol = protocol_factory->getProtocol(transport);
Person obj;
obj.read(protocol.get());
}
But when I run it, I encountered an error with message
terminate called after throwing an instance of 'apache::thrift::protocol::TProtocolException'
what(): Expected '"'; got 'n'.
Aborted (core dumped)
My thrift version is 0.12.0