将类似 JSON(但不是 JSON 格式)的字符串转换为 Java 对象

huangapple go评论75阅读模式
英文:

Convert json-like(not JSON) string to an object in Java

问题

我有一个类似的字符串:

{InstanceStatuses: [{AvailabilityZone: us-east-2b,Events: [],InstanceId: i-79e234fd, InstanceState: {Code: 16,Name: running},InstanceStatus: {Details: [{Name: reachability,Status: initializing}],Status: initializing},SystemStatus: {Details: [{Name: reachability,Status: initializing}],Status: initializing}}],}

如何将它转换为Java中的对象(类似哈希映射)?谢谢!

英文:

I have a string like:

{InstanceStatuses: [{AvailabilityZone: us-east-2b,Events: [],InstanceId: i-79e234fd, InstanceState: {Code: 16,Name: running},InstanceStatus: {Details: [{Name: reachability,Status: initializing}],Status: initializing},SystemStatus: {Details: [{Name: reachability,Status: initializing}],Status: initializing}}],}

how to convert it to an Object(like hashmap) in java? Thank you!

答案1

得分: 2

你从哪里获得这些字符串?因为如果是从亚马逊获取的(我在你的问题中看到了亚马逊标签),很可能已经存在一个(官方的)Java解析器。如果没有,我认为你唯一的机会就是自己编写一个解析器(可能会变得相当困难)。我认为你最好的选择是首先查找获取字符串的位置,然后搜索一个Java解析器。

英文:

Where do you get those strings? Because if it is from amazon (I see an amazon tag in your question) it is very likely that an (official) parser already exists for java.
If not, I think your only chance is to write a parser by your own (could get quite difficult).
I think your best choice for the start is to look where you get the string and then search for a java parser.

huangapple
  • 本文由 发表于 2020年4月7日 02:39:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/61066705.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定