英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论