简体   繁体   English

将字节数组从 PLC 转换为 JSON 或 Java 对象

[英]Convert byte array from PLC to JSON or Java Object

Is there a way to get a json or Java object out of an byte stream?有没有办法从字节流中获取 json 或 Java 对象?

If the structure in the plc looks like that如果plc中的结构看起来像这样

Data
  - id       int
  - pos      array[0..3] of int
  - time     dint

id=5
pos[0]=1
pos[1]=2
pos[2]=3
pos[3]=4
time = 5

I would get a bytearray of [0,5,0,1,0,2,0,3,0,4,0,0,0,5]我会得到一个[0,5,0,1,0,2,0,3,0,4,0,0,0,5]

Now I want a Json out of this like现在我想要一个像这样的 Json

{
  id:5,
  pos:[1,2,3,4],
  time:5
}

The Deserialization Process needs to know the Datatypes and the Array lengths .反序列化过程需要知道DatatypesArray lengths Is there any framework which supports things like that?有没有支持这样的框架?

JSON 只是文本,因此您可以将 JSON 对象转换为字符串,传输该字符串,然后将其转换回您正在使用的任何 JSON 库数据结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM