Java解析json字符串和json数组
Java解析json字符串和json数组
public static Map<String, String> getUploadTransactions(String json){ Map<String, String> map = new HashMap<String, String>(); JsonParser jsonParser = new JsonParser(); JsonObject jsonObject = (JsonObject)jsonParser.parse(json); String sha1 = jsonObject.get("sha1").getAsString(); String storekey = jsonObject.get("storekey").getAsString(); map.put("sha1", sha1); map.put("storekey", storekey); return map; } public static Map<String, String> getReturenTransactionCode(String json){ Map<String, String> map = new HashMap<String, String>(); JsonParser jsonParser = new JsonParser(); JsonObject jsonObject = (JsonObject)jsonParser.parse(json); String id = jsonObject.get("id").getAsString(); map.put("id", id); String feedback = jsonObject.get("feedback").getAsString(); map.put("feedback", feedback); JsonObject file_hashes_JsonObject = jsonObject.get("file_hashes").getAsJsonObject(); String sha1 = file_hashes_JsonObject.get("sha1").getAsString(); map.put("sha1", sha1); JsonArray upload_requests_jsonArray = jsonObject.get("upload_requests").getAsJsonArray(); JsonObject upload_requests_jsonArray_jsonObject = upload_requests_jsonArray.get(0).getAsJsonObject(); String type = upload_requests_jsonArray_jsonObject.get("type").getAsString(); map.put("type", type); JsonObject request_jsonObject = upload_requests_jsonArray_jsonObject.get("request").getAsJsonObject(); String method = request_jsonObject.get("method").getAsString(); map.put("method", method); String url = request_jsonObject.get("url").getAsString(); map.put("url", url); JsonArray header_array = request_jsonObject.get("header").getAsJsonArray(); for (int i = 0; i < header_array.size(); i++) { JsonObject heard_JsonObject = header_array.get(i).getAsJsonObject(); String header_name = heard_JsonObject.get("name").getAsString(); String header_value = heard_JsonObject.get("value").getAsString(); map.put(header_name, header_value); } return map; } public static Map<String, String> getSomeValumesCode(String json) { Map<String, String> map = new HashMap<String, String>(); JsonParser jsonParser = new JsonParser(); JsonObject jsonObject = (JsonObject)jsonParser.parse(json); JsonArray array = jsonObject.get("value").getAsJsonArray(); JsonObject object = array.get(0).getAsJsonObject(); String code = object.get("id").getAsString(); String name = object.get("name").getAsString(); String type = object.get("type").getAsString(); map.put("id", code); map.put("name", name); map.put("type", type); return map; } public static Integer getVolumesId(String json) { int valumesId = 0 ; JsonParser jsonParser = new JsonParser(); JsonObject jsonObject = (JsonObject)jsonParser.parse(json); JsonArray array = jsonObject.get("value").getAsJsonArray(); for (int i = 0; i < array.size(); i++) { JsonObject object = array.get(0).getAsJsonObject(); valumesId = object.get("id").getAsInt(); String name = object.get("name").getAsString(); //System.out.println(name); } return valumesId; }
http://graph.rst.ricoh.com/oauth2/token { "access_token": "czNcAISIJJLCy30XN9eYXjg6fm5IT6of_An7F2kt3eI.AAdG9BnhS6cZowQ_sUaBtEO-78wW-bxTsoZ_H9vu-Sg", "expires_in": 3599, "scope": "User.Files.Read User.Files.ReadWrite", "token_type": "bearer" } http://graph.rst.ricoh.com/api/v1/me/volumes { "value": [ { "id": "4053", "name": "我的文档", "company_id": "1", "created_by": { "user": { "id": "11" } }, "created_at": "2019-04-03T13:30:59+08:00", "updated_by": { "user": { "id": "11" } }, "updated_at": "2019-04-19T17:12:05+08:00" }, { "id": "4054", "name": "自动上传文档", "company_id": "1", "created_by": { "user": { "id": "11" } }, "created_at": "2019-04-03T13:30:59+08:00", "updated_by": { "user": { "id": "11" } }, "updated_at": "2019-04-03T13:30:59+08:00" } ] } http://graph.rst.ricoh.com/api/v1/me/volumes/4053 { "id": "4053", "name": "我的文档", "company_id": "1", "created_by": { "user": { "id": "11" } }, "created_at": "2019-04-03T13:30:59+08:00", "updated_by": { "user": { "id": "11" } }, "updated_at": "2019-04-19T17:12:05+08:00" } http://graph.rst.ricoh.com/api/v1/me/volumes/4053/files/root/children { "value": [ { "id": "4077", "name": "hbx", "type": "folder", "size": 0, "volume_id": "4053", "parent_id": "root", "hashes": { "sha1": "" }, "created_by": { "user": { "id": "11" } }, "created_at": "2019-04-19T17:13:10+08:00", "updated_by": { "user": { "id": "11" } }, "updated_at": "2019-04-19T17:13:10+08:00", "path": "" }, { "id": "4073", "name": "web.config", "type": "regular", "size": 75, "volume_id": "4053", "parent_id": "root", "hashes": { "sha1": "9cdf005be86a5e354b6311176e453e9e7875cdfe" }, "created_by": { "user": { "id": "11" } }, "created_at": "2019-04-19T16:30:00+08:00", "updated_by": { "user": { "id": "11" } }, "updated_at": "2019-04-19T16:30:00+08:00", "path": "" } ] } http://graph.rst.ricoh.com/api/v1/me/volumes/4053/files/root/children { "id": "4077", "name": "hbx", "type": "folder", "size": 0, "volume_id": "4053", "parent_id": "root", "hashes": { "sha1": "" }, "created_by": { "user": { "id": "11" } }, "created_at": "2019-04-19T17:13:10+08:00", "updated_by": { "user": { "id": "11" } }, "updated_at": "2019-04-19T17:13:10+08:00", "path": "" } http://graph.rst.ricoh.com/api/v1/me/volumes/4053/files/4077/upload-transactions { "id": "35233b59-ae97-4496-5672-bca8b2128c81", "storage": "s3", "file_hashes": { "sha1": "1e4002375dd8ba806ced48f6464bb7f1995659f8" }, "feedback": "4oRDGQ8kfRhbLoxaf7XvD1WV4dE=.eyJ0cmFuc2FjdGlvbl9pZCI6IjM1MjMzYjU5LWFlOTctNDQ5Ni01NjcyLWJjYThiMjEyOGM4MSIsInN0b3JhZ2VfdHlwZSI6InMzIiwiaXNfZmlsZV91cGRhdGUiOmZhbHNlLCJmaWxlX2lkIjowLCJmaWxlX25hbWUiOiJKYXZh5YWl6Zeo57uP5YW477yI5by654OI5o6o6I2Q77yJLnBkZiIsImZpbGVfbmFtZV9jb25mbGljdF9iZWhhdmlvciI6Im92ZXJ3cml0ZSIsImZpbGVfc2l6ZSI6MjkzODc3MSwiZmlsZV9oYXNoZXMiOnsic2hhMSI6IjFlNDAwMjM3NWRkOGJhODA2Y2VkNDhmNjQ2NGJiN2YxOTk1NjU5ZjgifSwiZmlsZV9rZXkiOiIzNTIzM2I1OS1hZTk3LTQ0OTYtNTY3Mi1iY2E4YjIxMjhjODEiLCJtdWx0aXBhcnRfdXBsb2FkX2lkIjoiIn0=", "upload_requests": [ { "type": "put_object", "request": { "method": "PUT", "url": "http://wps.rst.ricoh.com/minio/wpsfile/35233b59-ae97-4496-5672-bca8b2128c81", "header": [ { "name": "Content-Type", "value": "application/octet-stream" }, { "name": "Authorization", "value": "AWS4-HMAC-SHA256 Credential=LTAIf5lqDRk6W4Mf/20190419/us-east-1/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=1e83c6d9f5efa07282988e09fca1f727f4028bd05b24a6c34886a9a18f0568f4" }, { "name": "x-amz-content-sha256", "value": "UNSIGNED-PAYLOAD" }, { "name": "x-amz-date", "value": "20190419T094657Z" } ] } } ] } http://wps.rst.ricoh.com/minio/wpsfile/35233b59-ae97-4496-5672-bca8b2128c81 { "sha1": "a5abef21fe1e603f9bb419b23ea4d96b9615c66e", "storekey": "35233b59-ae97-4496-5672-bca8b2128c81" } http://graph.rst.ricoh.com/api/v1/me/volumes/4053/files/4077/upload-transactions/35233b59-ae97-4496-5672-bca8b2128c81 { "id": "35233b59-ae97-4496-5672-bca8b2128c81", "storage": "s3", "file_hashes": { "sha1": "1e4002375dd8ba806ced48f6464bb7f1995659f8" }, "status": "commited", "file": { "id": "4078", "name": "Java入门经典(强烈推荐).pdf", "type": "regular", "size": 2938771, "volume_id": "4053", "parent_id": "4077", "hashes": { "sha1": "1e4002375dd8ba806ced48f6464bb7f1995659f8" }, "created_by": { "user": { "id": "11" } }, "created_at": "2019-04-19T17:48:22+08:00", "updated_by": { "user": { "id": "11" } }, "updated_at": "2019-04-19T17:48:22+08:00", "path": "" } }