JSON

Convert an object to a JSON string with thrift json serializ

字号+ 作者:H5之家 来源:H5之家 2017-02-06 14:00 我要评论( )

Im new to the thrift. I need to convert my data object to a codeJSON string/code with codeThrift JSON/code serialization.[我是新来的节俭。我要将我的数

In here is an error, that object_name should be in TBase.

Next time, please post the exact error message (use copy+paste), this makes it easier for all of us.

How can I resolve this?

Whatever you want to serialize with Thrift, must be an descendant of Thrift's TBase class. You achieve this by writing some Thrift IDL and save it as a file (e.g. MyDataStructs.thrift):

struct Employee { 1: string name 2: string surname 3: i32 age }

Next, you pass that file to the Thrift compiler and tell him to generate some C# code from it:

thrift -gen csharp MyDataStructs.thrift

This gives you a class derived from TBase:

public partial class Employee : TBase { private string _name; private string _surname; private int _age; // properties public string Name {... } public string Surname { ... } public int Age { ... } // some details omitted public void Read (TProtocol iprot) { // generated code for Read() method } public void Write(TProtocol oprot) { // generated code for Write() method } public override string ToString() { // generated code for ToString() method } }

This is what Thrift expects.

在这里是一个错误,那object_name应tbase。

下一次,请发详细的错误信息(使用复制+粘贴),这使得它更容易对我们所有人。

我怎样才能解决这个问题?

无论你想序列化节俭,节俭是一个必须的后裔TBase类你通过写一些并保存为一个文件(例如MyDataStructs.thrift):

struct Employee { 1: string name 2: string surname 3: i32 age }

接下来,你通过文件要勤俭节约的编译器和告诉他从它产生一些C #代码:

thrift -gen csharp MyDataStructs.thrift

这给你来自tbase类:

public partial class Employee : TBase { private string _name; private string _surname; private int _age; // properties public string Name {... } public string Surname { ... } public int Age { ... } // some details omitted public void Read (TProtocol iprot) { // generated code for Read() method } public void Write(TProtocol oprot) { // generated code for Write() method } public override string ToString() { // generated code for ToString() method } }

这就是节俭预计。

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • json数组 是啥?

    json数组 是啥?

    2017-02-06 14:01

  • [ASP.net教程]生成json格式

    [ASP.net教程]生成json格式

    2017-02-06 11:00

  • 我的世界json模型文件图文教程

    我的世界json模型文件图文教程

    2017-02-06 10:02

  • JSON是什么?为JavaScript准备的数据格式

    JSON是什么?为JavaScript准备的数据格式

    2017-02-06 09:02

网友点评
v