永发信息网

node 怎么把buffer 转为json对象

答案:2  悬赏:80  手机版
解决时间 2021-01-25 10:07
node 怎么把buffer 转为json对象
最佳答案
前端传给服务器的只是json 格式的字符串,使用json_decode, mixed json_decode ( string $json [, bool $assoc ] ) var_dump(json_decode($json)); var_dump(json_decode($json, true)); 如果不带参数,则返回为对象 带上true时,返回数组 fore...
全部回答
例子: package org.protob; import org.protob.w.helloworld; import com.google.protobuf.invalidprotocolbufferexception; import com.googlecode.protobuf.format.jsonformat; import com.googlecode.protobuf.format.jsonformat.parseexception; public class main { public static void main(string[] args) throws exception { main2(null); main3(null); main4(null); } //序列化 /返序列化 public static void main2(string[] args) throws invalidprotocolbufferexception { //序列化 helloworld.builder builder=helloworld.newbuilder(); builder.setid(10); builder.setstr("fx"); builder.setopt(20); helloworld info=builder.build(); byte[] result=info.tobytearray() ; //返序列化 helloworld msg = helloworld.parsefrom(result); system.out.println(msg); } //protobuf转json public static void main3(string[] args) throws invalidprotocolbufferexception { //序列化 helloworld.builder builder=helloworld.newbuilder(); builder.setid(10); builder.setstr("fx"); builder.setopt(20); helloworld info=builder.build(); byte[] result=info.tobytearray() ; //返序列化 helloworld hello = helloworld.parsefrom(result); system.out.println(hello); string jsonformat =jsonformat.printtostring(hello); system.out.println(jsonformat); } //josn转protobuf public static void main4(string[] args) throws parseexception { helloworld.builder builder =helloworld.newbuilder(); string jsonformat = "{id:11,str:'xxx',opt:50}"; jsonformat.merge(jsonformat, builder); system.out.println(builder.build()); } } proto文件 w.proto package org.protob; message helloworld { required int32 id = 1; // id required string str = 2; // str optional int32 opt = 3; //optional field } 生成后的java类 // generated by the protocol buffer compiler. do not edit! // source: w.proto package org.protob; public final class w { private w() {} public static void registerallextensions( com.google.protobuf.extensionregistry registry) { } public interface helloworldorbuilder extends com.google.protobuf.messageorbuilder { // required int32 id = 1; /** * required int32 id = 1; * *
     * id 
     *
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
支付宝有7000积分可贷款多少钱
全国的中点大学都是那些?
已知,y=(x^2-2x+1/x^2-1)/(x^2-x)/(x+1)-(1
请问下北京市工商局公务员考试工商专业笔试都
哪个地方工资高
四马桥加油站地址在什么地方,我要处理点事
人进入青春期,会出现第二性征,下列不属于男
联想a706联系人怎么复制到卡里
有谁知道多啦A梦刚开始是怎么到大雄家的
消火栓箱套什么定额
liⅠy and eric( ) the dog at home。
久佳加油站地址在什么地方,我要处理点事
那些开广告招牌制作店的完全是靠关系吗?没有
我国东北、内蒙和新疆的部分地区处于同一纬度
年收入包括五险一金吗
推荐资讯
种植的树木直接长成椅子的形状
使m^4-m^2+4为完全平方数的自然数m有多少个,
甘肃省农村信用社(千户乡)地址在什么地方,想
雅迪悠米能行驶多少公里
通付手刷好用吗
红红小小水果叫什么刚熟不久,长的跟樱桃差不
丰收镇中心校地址在什么地方,想过去办事
三高人员能不能喝茉莉花茶?
禹城市房寺镇红星村幼儿园地址在什么地方,想
禹城市安仁镇张李店村幼儿园地址在什么地方,
苹果手机申请id账号为什么注册不了
先化解再求值 2(a*a)-3ab+(b*b)-(a*a)+ab-2
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?