gpt4 book ai didi

java - Android中解析字符串

转载 作者:行者123 更新时间:2023-12-01 08:09:33 25 4
gpt4 key购买 nike

我有一个从应用程序引擎数据存储上的“ContactInfo”实体中提取的字符串,并且在该字符串中它包含每种类型的所有子项。任何人对于如何解析它或以某种有序的方式组织它有任何好的想法。我需要它来显示每个条目的名字、姓氏、地址等,并为每个人单独显示一个。

这就是字符串记录的内容:

08-30 17:22:03.802: W/apples(18160): {"items":[{"description":"payment confirmed","emailAddress":"abc@aqw.com","id":"Fri Aug 30 17:20:35 EDT 2013","nameFirst":"Bill","nameLast":"Sanders","phone":"5555555555","state":"KS","streetAddress":"123 Rick Dr","zipCode":"44444","kind":"contactinfoendpoint#resourcesItem"},{"description":"payment confirmed","emailAddress":"qwe@msn.com","id":"Fri Aug 30 17:21:37 EDT 2013","nameFirst":"Frank","nameLast":"Lloyd","phone":"5554567896","state":"KY","streetAddress":"999 Rock St","zipCode":"44555","kind":"contactinfoendpoint#resourcesItem"}],"kind":"contactinfoendpoint#resources","etag":"\"NiDXI3T89oRrAPGJAhgGQje1Z0w/z0W4p01mjHc5cNgcOt3Kb_1xo8E\""}

最佳答案

您发布的字符串是一个 JSON 对象。

所以,你可以使用JSONObject class解析它,将其转换为对象,并以更舒适的方式访问其数据。

JSONObject jObject = new JSONObject(myString);

还要检查 GSON 或 Jackson,它们是第三方 JSON 解析器

关于java - Android中解析字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18541719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com