将 JSON 数据检索到列表视图中
我成功打开了 Httpclient
连接。现在我想从 JSON 选择数据并将其显示在列表中。我用谷歌搜索了半天,但找不到任何帮助。示例项目或代码片段会非常有帮助。
I successfully opened Httpclient
connection. Now I want to select data from JSON and show it in a list. I googled it from half day but can't find any help. A sample project or code snippet would be really helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
过去我使用 gson 来解析 JSON。 SDK中提供的org.json包看起来有点低级。
当您说“选择数据”时,您的意思是使用查询来检索数据的子集吗? jxpath 看起来是一个有趣的解决方案。如果您只是显示整个 JSON 数据,那么您应该能够简单地将 gson 的输出包装在适配器中。
最后一个会引导您这个问题< /a>,您的是完全相同的副本。
例子比比皆是!从上面的搜索链接来看:
In the past I've used gson to parse JSON. The
org.json
package provided in the SDK seems a little low-level.When you say "select data" do you mean use queries to retrieve subsets of your data? jxpath looks like an interesting solution. If you're just displaying the entire JSON data then you should be able to simply wrap gson's output in an adapter.
The last one would have led you to this question, of which yours is an exact duplicate.
Examples abound! From the above search links:
您必须使用 http://developer.android.com/reference/org /json/JSONTokener.html 或类似的内容来解码 JSON 数据。
完成此操作后,您需要更新列表视图上的列表模型。
我的印象是,对于您的应用程序 http://developer.android.com /reference/android/widget/ArrayAdapter.html 可能适合您的需求。
如果您已有阵列适配器,则可能只需要更新该适配器即可。
不过我没有具体细节。希望这会让您走上正轨。
You'll have to use http://developer.android.com/reference/org/json/JSONTokener.html or something similar to decode your JSON data.
After doing that you need to update your list model on your list view.
I'm under the impression that for your application http://developer.android.com/reference/android/widget/ArrayAdapter.html might suit your needs.
If you already have an array adapter, you probably just need to update that adapter.
I don't have specifics on that though. Hopefully this will put you on the right track.