Re: [protobuf] Re: MessageToJsonString output empty

2017-07-11 Thread 'Feng Xiao' via Protocol Buffers
On Sun, Jul 9, 2017 at 4:52 AM, hce h  wrote:

> Let me add more details, here is what I have a test program:
>
> test.proto:
>
> syntax = "proto3";
> package test;
>
> message TestMessage {
> string query = 1;
> int32 page_number = 2;  // Which page number do we want?
> int32 result_per_page = 3;  // Number of results to return per page.
> }
>
> test::TestMessage message;
>
If you don't set any value in the message, the JSON output is expected to
be empty.

If you want to print out values even not set, try the
always_print_primitive_fields flag:
https://github.com/google/protobuf/blob/master/src/google/protobuf/util/json_util.h#L63


> std::string output;
> google::protobuf::util::MessageToJsonString(message, );
> printf("Convert: %d %s\n", output.length(), output.c_str());
>
> Convert: 2 {}
>
>
>
>
>
>
> On Sunday, July 9, 2017 at 1:01:39 PM UTC+10, hce h wrote:
>>
>> Hi,
>>
>> I tried to call MessageToJsonString on Protobuf 3.3.0, but the output string 
>> was empty, output = "{}". Has anyone made it work? If so, could you please 
>> show me an example?
>>
>> Thank you.
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] Re: MessageToJsonString output empty

2017-07-09 Thread hce h
Let me add more details, here is what I have a test program:

test.proto:

syntax = "proto3";
package test;

message TestMessage {
string query = 1;
int32 page_number = 2;  // Which page number do we want?
int32 result_per_page = 3;  // Number of results to return per page.
}

test::TestMessage message;
std::string output;
google::protobuf::util::MessageToJsonString(message, );
printf("Convert: %d %s\n", output.length(), output.c_str());

Convert: 2 {}





On Sunday, July 9, 2017 at 1:01:39 PM UTC+10, hce h wrote:
>
> Hi,
>
> I tried to call MessageToJsonString on Protobuf 3.3.0, but the output string 
> was empty, output = "{}". Has anyone made it work? If so, could you please 
> show me an example?
>
> Thank you.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.