Hi Feng,

Thanks for the reply.

On Wednesday, 10 May 2017 20:19:09 UTC+2, Feng Xiao wrote:
>
>
>
> On Wed, May 10, 2017 at 7:51 AM, Wayde Leverington <[email protected] 
> <javascript:>> wrote:
>
>> Hi,
>>
>> I currently trying to parse a json array to protobuf 
>> using JsonStringToMessage method. 
>>
>> Example Json:
>> [
>>   {
>>     Name:"Bob",
>>     Age:24
>>   },
>>   {
>>     Name:"John",
>>     Age:12
>>   },
>>  {
>>     Name:"Pat",
>>     Age:64
>>   }
>> ]
>>  
>> Example Proto:
>> syntax = "proto3";
>>
>> message Person{
>>     string name = 1 [json_name = "Name"];
>>     int32 age= 2 [json_name = "Age"];
>>   }
>>   
>> message PersonList{  
>>   repeated Person personList = 1;
>> }
>>
>>
>> Currently this throws an error "INVALID_ARGUMENT:: Root element must be a 
>> message.". Is there a way to setup a protobuf to allows an anonymous json 
>> root?
>>
> Right now JsonStringToMessage works on a message object and expects a JSON 
> object as the input. You can wrap your JSON array like this to make it work:
> {"personList": [ ... your array data ... ]}
>
>  
>
>>
>> -- 
>> 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 [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to