我正在使用simple_Json,我在网上看到了将JSON响应转换为JSON对象数组的示例。
这是我如何尝试获取数组,但不确定为什么我没有获得jason数组的方法。
JSONObject jsonObject =(JSONObject)new JSONParser().parse(response.toString());
JSONObject s = (JSONObject)jsonObject.get("GetMyRootFoldersForTreeResult");
JSONArray array = /** Not sure how to get array */
这是JSON响应:
{"GetMyRootFoldersForTreeResult":[{"Folder":{"isDirty":false,"isNew":false,"AllTagsData":null,"Archived":false,"ArchivedBy":null,"ArchivedDate":"\/Date(-6847824600000+0530)\/","CreatedBy":"SYSTEM","CreatedOnDate":"\/Date(1321523609427+0530)\/","EntityDescription":null,"EntityName":"System","ModifiedBy":"SYSTEM","ModifiedDate":"\/Date(1321523609427+0530)\/","State":null,"AdministratorViewOnly":false,"EntityFolderID":null,"Hidden":false,"HistoryFolderID":null,"CanBeRoot":true,"DefaultPageName":null,"FolderBehaviorType":"DecisionsFramework.ServiceLayer.Utilities.SystemFolder","FolderID":"SYSTEM FOLDER","FolderTypeName":"Folder","FullPath":"System","HasSubFolders":true,"IsSecurityFolder":true,"IsSystemFolder":true,"NestingLevel":1,"SecurityFolderId":"SYSTEM FOLDER","ShowInTree":true,"SubMenuBehavior":0,"SubMenuGroupName":null},"HasSubFolders":true},{"Folder":{"isDirty":false,"isNew":false,"AllTagsData":null,"Archived":false,"ArchivedBy":null,"ArchivedDate":"\/Date(-6847824600000+0530)\/","CreatedBy":"SYSTEM","CreatedOnDate":"\/Date(1321523675797+0530)\/","EntityDescription":null,"EntityName":"CMDB","ModifiedBy":"SYSTEM","ModifiedDate":"\/Date(1321523675797+0530)\/","State":null,"AdministratorViewOnly":false,"EntityFolderID":null,"Hidden":false,"HistoryFolderID":null,"CanBeRoot":true,"DefaultPageName":null,"FolderBehaviorType":"Decisions.TaskTracking.Service.Asset.AssetFolderBehavior","FolderID":"Asset_BASE_FOLDER_ID","FolderTypeName":"Asset Folder","FullPath":"CMDB","HasSubFolders":false,"IsSecurityFolder":true,"IsSystemFolder":false,"NestingLevel":1,"SecurityFolderId":"Asset_BASE_FOLDER_ID","ShowInTree":true,"SubMenuBehavior":0,"SubMenuGroupName":null},"HasSubFolders":false},{"
我想获取文件夹数组。
答案 0 :(得分:2)
JSONObject jsonObject =(JSONObject)new JSONParser().parse(response.toString());
JSONArray array = jsonObject.getJSONArray("GetMyRootFoldersForTreeResult");
试试这个。
答案 1 :(得分:2)
simple-json
没有这些方法。请改用java-json.jar
。