Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android JSON数据列表动态_Android_Json - Fatal编程技术网

Android JSON数据列表动态

Android JSON数据列表动态,android,json,Android,Json,我在安卓系统工作只是为了提高警惕。我能够检索JSON数据,但现在我已经到了有倍数的地步。例如: "workers":[ { "id":3357, "username":"Unreliable.worker", "password":"x", "monitor":0,

我在安卓系统工作只是为了提高警惕。我能够检索JSON数据,但现在我已经到了有倍数的地步。例如:

"workers":[
                {
                    "id":3357,
                    "username":"Unreliable.worker",
                    "password":"x",
                    "monitor":0,
                    "count_all":41,
                    "count_all_archive":0,
                    "hashrate":477,
                    "difficulty":106.56
                },
                {
                    "id":4061,
                    "username":"Unreliable.worker2",
                    "password":"x",
                    "monitor":0,
                    "count_all":0,
                    "count_all_archive":null,
                    "hashrate":0,
                    "difficulty":0
                }
我需要做一个for循环,还是有其他方法

这是我现在用来获取它们的代码:

JSONObject workersJSONObject = personalJSONObject.getJSONObject("workers");
但我不知道我会如何得到每一个和分开他们。我将使用以下方法获取它们:

id= workersJSONObject.getDouble("id");

JSON中的
[]
指的是
JSON数组
。您可以使用以下内容:

JSONArray workersJSONArray = personalJSONObject.getJSONArray("workers");
然后将每个项循环为(基本上获取
数组中的每个
对象
):

for(int i=0;i
在JSON上,{}定义了一个对象,[]定义了一个数组。如果你想知道细节。看到和

样本:

JSONArray workersJSOnArray = new JSONArray(stringData);
   or 
JSONArray workersJSOnArray = personalJSONObject.getJSONArray("workers");


/* THen you can loop from each data you want */
int len = workersJSOnArray.length();
for (int i = 0; i < len; i++)
{
   JSONObject item = workersJSOnArray.optJSONObject(i);

   int id = item.getInt ("id");
   .....
}   
JSONArray-workersJSOnArray=新的JSONArray(stringData);
或
JSONArray workersJSOnArray=personalJSONObject.getJSONArray(“workers”);
/*然后可以从所需的每个数据循环*/
int len=workersJSOnArray.length();
对于(int i=0;i
JSONArray workersJSOnArray = new JSONArray(stringData);
   or 
JSONArray workersJSOnArray = personalJSONObject.getJSONArray("workers");


/* THen you can loop from each data you want */
int len = workersJSOnArray.length();
for (int i = 0; i < len; i++)
{
   JSONObject item = workersJSOnArray.optJSONObject(i);

   int id = item.getInt ("id");
   .....
}