当前位置: 首页 > 知识库问答 >
问题:

如何在PHP中解析来自google drive API get文件的json响应

阳勇
2023-03-14

我得到这个响应从curl到https://www.googleapis.com/drive/v2/files?q='[文件夹ID]'在父母

{ "kind": "drive#fileList", "etag": "\"sUwP36qaD260RUkBRZNiE0CB3Hg/9BIQNPy_h12YATGHr4uxbE86-kk\"", "selfLink": "https://www.googleapis.com/drive/v2/files?q='1kbHKqYhX9ZjWjAjE-9viiZ7AsL5HJVIO'+in+parents", "incompleteSearch": false, "items": [ { "kind": "drive#file", "id": "19WK5HWnV0x2u0fDXugrisJRG7ZKOHOds", "etag": "\"sUwP36qaD260RUkBRZNiE0CB3Hg/MTUxMDIxMTQ2OTY2Mw\"", "selfLink": "https://www.googleapis.com/drive/v2/files/19WK5HWnV0x2u0fDXugrisJRG7ZKOHOds", "webContentLink": "https://drive.google.com/uc?id=19WK5HWnV0x2u0fDXugrisJRG7ZKOHOds&export=download", "alternateLink": "https://drive.google.com/file/d/19WK5HWnV0x2u0fDXugrisJRG7ZKOHOds/view?usp=drivesdk", "embedLink": "https://drive.google.com/file/d/19WK5HWnV0x2u0fDXugrisJRG7ZKOHOds/preview?usp=drivesdk", "iconLink": "https://drive-thirdparty.googleusercontent.com/16/type/application/x-rar", "title": "Ab Du BD 720p.rar", "mimeType": "application/x-rar", "labels": { "starred": false, "hidden": false, "trashed": false, "restricted": false, "viewed": false }, "copyRequiresWriterPermission": false, "createdDate": "2017-11-09T07:10:47.865Z", "modifiedDate": "2017-11-09T07:11:09.663Z", "markedViewedByMeDate": "1970-01-01T00:00:00.000Z", "version": "19", "parents": [ { "kind": "drive#parentReference", "id": "1kbHKqYhX9ZjWjAjE-9viiZ7AsL5HJVIO", "selfLink": "https://www.googleapis.com/drive/v2/files/19WK5HWnV0x2u0fDXugrisJRG7ZKOHOds/parents/1kbHKqYhX9ZjWjAjE-9viiZ7AsL5HJVIO", "parentLink": "https://www.googleapis.com/drive/v2/files/1kbHKqYhX9ZjWjAjE-9viiZ7AsL5HJVIO", "isRoot": false } ], "downloadUrl": "https://doc-10-a4-docs.googleusercontent.com/docs/securesc/o7l0aeqi0drljltr83c3565k9441n6of/1313an8qmrf0v4n7do9ppsqhpf45dmqk/1549094400000/05301767890081372214/13058876669334088843/19WK5HWnV0x2u0fDXugrisJRG7ZKOHOds?e=download&gd=true", "userPermission": { "kind": "drive#permission", "etag": "\"sUwP36qaD260RUkBRZNiE0CB3Hg/3cxCmsajfyZJPGtyQXwHveV8jkI\"", "id": "me", "selfLink": "https://www.googleapis.com/drive/v2/files/19WK5HWnV0x2u0fDXugrisJRG7ZKOHOds/permissions/me", "role": "writer", "type": "user" }, "originalFilename": "Salinan [Drivenime] Ab Du BD 720p.rar", "fileExtension": "rar", "md5Checksum": "62504a3df8228c3c573af2c4d48d2499", "fileSize": "3193962228", "quotaBytesUsed": "0", "ownerNames": [ "Handriand Excalibur" ], "owners": [ { "kind": "drive#user", "displayName": "Handriand Excalibur", "picture": { "url": "https://lh6.googleusercontent.com/-H-Zbopmf3KU/AAAAAAAAAAI/AAAAAAAAAAc/PZkxPa0oZ8w/s64/photo.jpg" }, "isAuthenticatedUser": false, "permissionId": "05301767890081372214", "emailAddress": "handriand@nekohime.us" } ], "lastModifyingUserName": "Handriand Excalibur", "lastModifyingUser": { "kind": "drive#user", "displayName": "Handriand Excalibur", "picture": { "url": "https://lh6.googleusercontent.com/-H-Zbopmf3KU/AAAAAAAAAAI/AAAAAAAAAAc/PZkxPa0oZ8w/s64/photo.jpg" }, "isAuthenticatedUser": false, "permissionId": "05301767890081372214", "emailAddress": "handriand@nekohime.us" }, "capabilities": { "canCopy": false, "canEdit": true }, "editable": true, "copyable": false, "writersCanShare": true, "shared": true, "explicitlyTrashed": false, "appDataContents": false, "headRevisionId": "0B_K_rT1g5fo7K0x5NTUraGR2VkRUOHQ0ZXlaQkhTcEErSXFzPQ", "spaces": [ "drive" ] }, { "kind": "drive#file", "id": "1pp6ydlrDn1GlHpp6iV7asOY5q5mklPMJ", "etag": "\"sUwP36qaD260RUkBRZNiE0CB3Hg/MTUxMDIxMTQ2MzMxMg\"", "selfLink": "https://www.googleapis.com/drive/v2/files/1pp6ydlrDn1GlHpp6iV7asOY5q5mklPMJ", "webContentLink": "https://drive.google.com/uc?id=1pp6ydlrDn1GlHpp6iV7asOY5q5mklPMJ&export=download", "alternateLink": "https://drive.google.com/file/d/1pp6ydlrDn1GlHpp6iV7asOY5q5mklPMJ/view?usp=drivesdk", "embedLink": "https://drive.google.com/file/d/1pp6ydlrDn1GlHpp6iV7asOY5q5mklPMJ/preview?usp=drivesdk", "iconLink": "https://drive-thirdparty.googleusercontent.com/16/type/application/x-rar", "title": "Ab Du BD 480p.rar", "mimeType": "application/x-rar", "labels": { "starred": false, "hidden": false, "trashed": false, "restricted": false, "viewed": false }, "copyRequiresWriterPermission": false, "createdDate": "2017-11-09T07:10:47.865Z", "modifiedDate": "2017-11-09T07:11:03.312Z", "markedViewedByMeDate": "1970-01-01T00:00:00.000Z", "version": "19", "parents": [ { "kind": "drive#parentReference", "id": "1kbHKqYhX9ZjWjAjE-9viiZ7AsL5HJVIO", "selfLink": "https://www.googleapis.com/drive/v2/files/1pp6ydlrDn1GlHpp6iV7asOY5q5mklPMJ/parents/1kbHKqYhX9ZjWjAjE-9viiZ7AsL5HJVIO", "parentLink": "https://www.googleapis.com/drive/v2/files/1kbHKqYhX9ZjWjAjE-9viiZ7AsL5HJVIO", "isRoot": false } ], "downloadUrl": "https://doc-0s-a4-docs.googleusercontent.com/docs/securesc/o7l0aeqi0drljltr83c3565k9441n6of/nirvirens1boiduikeggb5dfon0d09e0/1549094400000/05301767890081372214/13058876669334088843/1pp6ydlrDn1GlHpp6iV7asOY5q5mklPMJ?e=download&gd=true", "userPermission": { "kind": "drive#permission", "etag": "\"sUwP36qaD260RUkBRZNiE0CB3Hg/A25TTqDBXh9qHAVoQR0peuvGl6w\"", "id": "me", "selfLink": "https://www.googleapis.com/drive/v2/files/1pp6ydlrDn1GlHpp6iV7asOY5q5mklPMJ/permissions/me", "role": "writer", "type": "user" }, "originalFilename": "Salinan [Drivenime] Ab Du BD 480p.rar", "fileExtension": "rar", "md5Checksum": "0aa1a38cf7474c479f7941f8d31ad2b2", "fileSize": "955429275", "quotaBytesUsed": "0", "ownerNames": [ "Handriand Excalibur" ], "owners": [ { "kind": "drive#user", "displayName": "Handriand Excalibur", "picture": { "url": "https://lh6.googleusercontent.com/-H-Zbopmf3KU/AAAAAAAAAAI/AAAAAAAAAAc/PZkxPa0oZ8w/s64/photo.jpg" }, "isAuthenticatedUser": false, "permissionId": "05301767890081372214", "emailAddress": "handriand@nekohime.us" } ], "lastModifyingUserName": "Handriand Excalibur", "lastModifyingUser": { "kind": "drive#user", "displayName": "Handriand Excalibur", "picture": { "url": "https://lh6.googleusercontent.com/-H-Zbopmf3KU/AAAAAAAAAAI/AAAAAAAAAAc/PZkxPa0oZ8w/s64/photo.jpg" }, "isAuthenticatedUser": false, "permissionId": "05301767890081372214", "emailAddress": "handriand@nekohime.us" }, "capabilities": { "canCopy": false, "canEdit": true }, "editable": true, "copyable": false, "writersCanShare": true, "shared": true, "explicitlyTrashed": false, "appDataContents": false, "headRevisionId": "0B_K_rT1g5fo7VVo0MUlCMFFQcVRyTytYRXhZcWtSbTlFMzBnPQ", "spaces": [ "drive" ] } ] }

欲知详情,请浏览https://pastebin.com/acytLfN7

这将获得驱动器上文件夹中的所有文件,然后我想在表或任何文件中显示它。我如何解析它?我想以[title]-[selfLink]-[mimeType]为例

我已经试过了

foreach($list as $f){
    echo $f[title];
    echo $f[items][title];
    echo $f[items]->title;
}

仍然不能得到值总是得到d"h在屏幕上这个结果我尝试

共有1个答案

苏洛城
2023-03-14

您正在处理对象而不是数组,您将需要循环遍历项目:

$json = '//RETURNED JSON';
$all_files = json_decode($json);

foreach($all_files->items as $files){
    echo $files->title;
    echo $files->selfLink;
    echo $files->mimeType;
}
 类似资料:
  • 问题内容: 我试图使用PHP解析JSON文件。但是我现在被困住了。 这是我的JSON文件的内容: 到目前为止,这是我尝试过的: 但是,因为我不知道的名字(例如,)和所有可用键和值(如,)事前,我想我需要创建一些foreach循环。 我希望为此举一个例子。 问题答案: 要遍历多维数组,可以使用RecursiveArrayIterator 输出:

  • 问题内容: 给定以下文件,该文件包含HTTP请求和HTTP响应的HTTP流水线流。 如何将该文件解析为变量? 原始文件: 我知道有http.ReadRequest。那回应呢?任何想法/反馈/想法表示赞赏。 问题答案: 实际上非常简单: 一些注意事项: 有和 并可以在相同的位置上反复调用,直到它“正常工作” “正常工作”取决于Content-Length标头的存在和正确性,因此读取正文会将Reade

  • 问题内容: 我收到此响应的结果是对服务器的GET请求 我只想从上述json响应中提取的值。 我正在使用此代码来获得此响应 我的问题是,我该如何解析并获取only 标签的值。谢谢 问题答案: 您可以解析当前的json字符串以从中获取它:

  • 问题内容: 我想解析以下Json响应: 我尝试使用SIMPLE JSON解析器,但这对我不起作用: 问题答案: 输出: 评论: 我没有添加验证 [编辑] 加载json字符串的其他方法

  • 问题内容: 到目前为止,我的目标是在Rust中解析此JSON数据: 并且是 我下一步应该解析什么?我的主要目标是获取这样的JSON数据,并从其中解析密钥(例如Age)。 问题答案: Serde是首选的JSON序列化提供程序。您可以通过多种方式从文件中读取JSON文本。将其作为字符串使用后,请使用: Cargo.toml: 您甚至可以使用类似的方法直接从已打开的读取。 Serde可以用于JSON以外

  • 问题内容: 我正在尝试从JSON文件解析数据。我试图将已解析/获取的数据放入带有标签的UIView或Webview中。JSON文件如下所示: 在上有一些帖子,展示了如何解析从WebURL检索到的JSON,但实际上我已经有一个要解析的JSON文件。如何从文件解析JSON? 问题答案: 创建空的文本文件(新文件/其他/空),例如“ example.json” 将json字符串粘贴到文件中。 使用以下行