android – 将JSON解析为ListView友好输出

android – 将JSON解析为ListView友好输出,第1张

概述所以我有这个 JSON,然后我的活动检索到一个字符串: {"popular": {"authors_last_month": [ { "url":"http://activeden.net/user/OXYLUS", "item":"OXYLUS", "sales":"1148", 所以我有这个 JSON,然后我的活动检索到一个字符串:
{"popular":        {"authors_last_month": [         {            "url":"http://activeden.net/user/OXYLUS","item":"OXYLUS","sales":"1148","image":"http://s3.envato.com/files/15599.jpg"         },{            "url":"http://activeden.net/user/digitalscIEnce","item":"digitalscIEnce","sales":"681","image":"http://s3.envato.com/files/232005.jpg"         }         {            ...         }        ],"items_last_week": [         {            "cost":"4.00","thumbnail":"http://s3.envato.com/files/227943.jpg","url":"http://activeden.net/item/christmas-decoration-balls/75682","sales":"43","item":"Christmas decoration Balls","rating":"3","ID":"75682"         },{            "cost":"30.00","thumbnail":"http://s3.envato.com/files/226221.jpg","url":"http://activeden.net/item/xml-flip-book-as3/63869","sales":"27","item":"XML Flip Book / AS3","rating":"5","ID":"63869"         },{            ...         }],"items_last_three_months": [         {            "cost":"5.00","thumbnail":"http://s3.envato.com/files/195638.jpg","url":"http://activeden.net/item/image-logo-shiner-effect/55085","sales":"641","item":"image logo shiner effect","ID":"55085"         },{            "cost":"15.00","thumbnail":"http://s3.envato.com/files/180749.png","url":"http://activeden.net/item/banner-rotator-with-auto-delay-time/22243","sales":"533","item":"BANNER rotator with auto Delay Time","ID":"22243"},{            ...         }]    }}

它也可以被访问here,虽然因为它是一个很长的字符串,我已经修改了上面的内容以显示所需的内容.

基本上,我希望能够访问“items_last_week”中的项目并创建它们的列表 – 最初我的计划是在左侧显示“缩略图”,旁边有“项目”,但是从今天的SDK看起来太难或不可能实现这一点,所以我很高兴只从列表中的’items_last_week’获取’item’数据.

来自PHP我很难使用任何可用于Java的JsON库,因为它看起来不仅仅是一行代码,我需要反序列化(我认为这是正确的词)JsON,以及它们似乎都需要某种形式的附加类,除了JsONArray / JsONObject脚本我不喜欢items_last_week嵌套的事实(再次,我认为这是JsON术语)并且需要很长时间才能运行AndroID模拟器.

因此,实际上,我需要一种(最好是简单的)方法将items_last_week数据传递给ListVIEw.我知道我需要一个自定义适配器,我可能会理解,但我无法理解,无论我花了多少时间试图找出它,如何访问JsON字符串的某些部分..

解决方法

originally my plan was to have the
‘thumbnail’ on the left with the
‘item’ next to it,but from playing
around with the SDK today it appears
too difficult or impossible to achIEve
this

这远非不可能,但除非你为你使用something that already wraps up that pattern(并且希望合理地说“正确”),否则做出正确的做法将是乏味的.在Web上,性能/带宽问题是用户的问题 – 在移动设备中,它们是您的问题.

as it appears to be much more than a
line of code which I will need to
deserialize (I think that’s the right
word) the JsON

新的JsONObject(数据)是一行代码.现在,从前面提到的URL获取JsON(我认为你正在做的)将是几行代码.解析JsON或从互联网上获取它都不是AndroID独有的 – 所有这些在桌面Java应用程序或Java servlet或其他任何东西上看起来都是一样的.

apart from the JsONArray/JsONObject
script I have which doesn’t like the
fact that items_last_week is nested

我没有遇到像文件展示这样的结构解析JsON的问题.此外,这几乎不是AndroID独有的 – JsON解析器在许多其他基于Java的项目中使用.

and takes an awful long time to run on
the AndroID emulator

仿真器的速度与开发机器的速度有关.对我来说,模拟器通常比实际的手机硬件慢…而我的桌面是四核的.请记住,仿真器假装是在PC上运行的ARM芯片组,即时将ARM *** 作码转换为x86 *** 作码,因此它不会很快,也不会很好地利用多个内核.

So,in effect,I need a (preferably
simple) way to pass the
items_last_week data to a ListVIEw.

AndroID中没有任何内置功能可以使用任意数据采用任意JsON结构,并将其直接转换为ListVIEw.这不是JsON独有的 – XML会出现类似的现象.

你的选择是:

>创建一个包装已解析JsON的自定义listadapter.
>将解析后的JsON转换为MatrixCursor(想想2D数据数组)并使用SimpleCursorAdapter.
>将解析后的JsON转换为ArrayList< String>并使用ArrayAdapter.

从短期来看,选项#3可能是最简单的.

I understand I will need a custom
adapter which I can probably get my
head around but I cannot understand,
no matter how much of the day I’ve
just spent trying to figure it out,
how to access certain parts of a JsON
string..

这个问题在援助方面太过模糊.您可以考虑打开一个单独的问题,标记为Java和JsON,您可以在其中详细了解Json.org解析器遇到问题的位置.

总结

以上是内存溢出为你收集整理的android – 将JSON解析为ListView友好输出全部内容,希望文章能够帮你解决android – 将JSON解析为ListView友好输出所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1130767.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存