Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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
无键值的Java JSON数据_Java_Json - Fatal编程技术网

无键值的Java JSON数据

无键值的Java JSON数据,java,json,Java,Json,这是我试图读取的有问题的JSON数据: "555":{ "ID":115, "name":"John Smith", "email":"john@gmail.com", "tel":"0123456789" }, "568":{ "ID":221, "name":"Xxxx xxxxx", "email":"xxxx@gmail.com", "tel":"0123456789" }} 我想读取id、姓名和电子邮件并用“\t”分隔,

这是我试图读取的有问题的JSON数据:

"555":{
    "ID":115,
    "name":"John Smith",
    "email":"john@gmail.com",
    "tel":"0123456789"
},
"568":{
    "ID":221,
    "name":"Xxxx xxxxx",
    "email":"xxxx@gmail.com",
    "tel":"0123456789"
}}
我想读取id、姓名和电子邮件并用“\t”分隔,但我不知道键值,因为它是通过随机函数生成的

String data;
JSONObject json = new JSONObject(sb.toString()); / sb is StringBuffer
String[] keyValues = JSONObject.getNames(json);
for(int i=0; keyValues.length < i; i++) {
   data = jsonObj.getString(keyValues[i]);
}
字符串数据;
JSONObject json=新的JSONObject(sb.toString());/某人被解雇了
String[]keyValues=JSONObject.getNames(json);
对于(int i=0;keyValues.length

我在这里遇到了一些JSON Java示例,但没有类似的例子。有人能告诉我哪里错了吗?

JSON支持对象作为对象的子对象。
getJSONObject()
方法对于检索这些子对象非常有用

for(int i=0; keyValues.length < i; i++) {
  JSONObject obj = jsonObj.getJSONObject(keyValues[i]);
  System.out.println (obj.getInt("ID")+" "+obj.getString("name");
}
for(int i=0;keyValues.length
参考: