提取JSONObject并通过HashMap字段进行迭代 [英] Extract JSONObject and iterate through HashMap field

查看:128
本文介绍了提取JSONObject并通过HashMap字段进行迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遍历JSONObject的值(即hashMap).

I am trying to iterate through a value (that is a hashMap) of a JSONObject.

首先,我得到一个服务器响应,它是一个字符串.

First I get a server response that is a String.

然后我将其转换为字符串!像这样:

Then I turn it into a String! like this:

val responseString = response.serverResponse

然后我将其变成这样的JSONObject:

Then I turn it into a JSONObject like this:

val jsonObj = JSONObject(responseString.toString()).get("data")

我执行第二步,因为我只想保留所附图片中所示的LinkedHashMap. 但是第二步返回类型"Any".然后我无法遍历LinkedHashMap

I do the second step because I only want to keep the LinkedHashMap shown in the picture attached. But the second step returns type "Any" and then I cant iterate through the LinkedHashMap

推荐答案

JSONObject myjsonObject = new JSONObject();
迭代器键值= jsonObject.keys();

JSONObject myjsonObject = new JSONObject();
Iterator keyvalues = jsonObject.keys();

while(keys.hasNext()){String key = keyvalues.next(); if(myjsonObject的myjsonObject.get(key)实例){

while(keys.hasNext()) {String key = keyvalues.next(); if (myjsonObject.get(key) instanceof myjsonObject) {

}

}

这篇关于提取JSONObject并通过HashMap字段进行迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆