我正在掌握 JAVA 的 GSON,并且有一个关于如何从我正在使用的大型 json 文档中进行类似 jsonpath 的选择的问题。
例如,使用如下 json 文档:
{
"environment": {
"red": {
"area": {
"1": {
"name": "foo"
},
"2": {
"name": "bar"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
jsonpath 表达式:
$.environment.red.area
Run Code Online (Sandbox Code Playgroud)
返回:
[
{
"1": {
"name": "foo"
},
"2": {
"name": "bar"
}
}
]
Run Code Online (Sandbox Code Playgroud)
在GSON中如何实现这种选择呢?
我不清楚该问题被标记为重复的问题的答案。似乎说它可以在 GSON 中完成,但没有说明或显示如何完成(据我所知)。
我正在使用以下
resource "google_service_account" "store_user" {
account_id = "store-user"
display_name = "Storage User"
}
resource "google_project_iam_binding" "store_user" {
project = var.project_id
role = "roles/storage.admin"
members = [
"serviceAccount:${google_service_account.store_user.email}"
]
}
Run Code Online (Sandbox Code Playgroud)
效果很好,因为它创建了 SA 并为其分配了存储管理员角色。伟大的。但我需要为这个 SA 分配大约 4 个角色。我尝试了各种方法,包括使用带有重复绑定/角色块的数据块,如下所示:
data "google_iam_policy" "store_user_roles" {
binding {
role = "roles/storage.admin"
members = [
"serviceAccount:${google_service_account.store_user.email}",
]
}
binding {
role = "roles/pubsub.admin"
members = [
"serviceAccount:${google_service_account.store_user.email}",
]
}
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,它运行了,但 SA 没有获得角色/权限。我尝试过到处找到的各种其他示例,但没有成功。有人可以在正确的方向上推动我如何实现这一目标吗?
// 更新。以下对我有用:
resource "google_project_iam_binding" "storage-iam" {
project = var.project_id
role = "roles/storage.admin"
members = …Run Code Online (Sandbox Code Playgroud) 完全改写问题,因为第一次尝试尚不清楚。
在我的逻辑应用程序中,我正在从 blob 读取 .json,其中包含:
{
"alpha": {
"url": "https://linktoalpha.com",
"meta": "This logic app does job aaaa"
},
"beta": {
"url": "https://linktobeta.com",
"meta": "This logic app does job beta"
},
"theta": {
"url": "https://linktotheta.com",
"meta": "This logic app does job theta"
}
}
Run Code Online (Sandbox Code Playgroud)
我使用正文中包含的 http 帖子触发逻辑应用程序:
{ "logicappname": "beta" }
Run Code Online (Sandbox Code Playgroud)
但“logicappname”的值可以是 alpha、beta 或 theta。我现在需要设置一个包含“beta”的 url 值的变量。如果没有 jsonpath 支持,如何实现这一点?
我已经使用 json 解析 blob 中的文件内容,这给了我令牌...但我不知道如何选择我需要的值。希望有任何帮助,谢谢。
我正在使用深度嵌套的 JSON,并且在 Convertfrom-json 之后,需要能够遍历 Convertfrom-json cmdlet 生成的对象的各个部分。
我无法提前知道对象内部可能存在或不存在哪些属性名称,据我所知,有数百种不同的可能属性。幸运的是,我看到有帮助的一件事是我关心的每个属性都是“NoteProperty”类型。
这是一个例子:
TypeName: System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
definition NoteProperty System.Management.Automation.PSCustomObject definition=@{$schema=https://schema.management.azure.com/providers/Microsof...
integrationAccount NoteProperty System.Management.Automation.PSCustomObject integrationAccount=@{id=[parameters('integrationAccounts_xxx_integration...
parameters NoteProperty System.Management.Automation.PSCustomObject parameters=@{$connections=}
state NoteProperty string state=Enabled
Run Code Online (Sandbox Code Playgroud)
因此,我认为创建一个仅选择当前正在处理的级别的对象(“MemberType”“NoteProperty”)的函数会很简单。
我尝试将对象通过管道传输到:
where-object { $_.MemberType -eq "NoteProperty" }
Run Code Online (Sandbox Code Playgroud)
没有。
我也尝试过各种形式的选择对象,但似乎无法选择我需要的东西。我发现脚本人员写的一篇关于使用标签和表达式的旧文章 - 但这似乎有点过头了,不是吗?有人可以指出我仅选择 NoteProperty 项目的简单方法吗?
谢谢!
我正在使用Rest API并收集了一块Json的粗糙块.我正在运行convertfrom-json来获取一个我想操作的powershell对象.基本上我需要修剪一些字段/值.
没有问题要"获取"我想要从对象中删除的字段,因为我可以深入到字段并收集容易的值,我被卡住的是如何从posh对象中删除该字段.非常感谢任何帮助.谢谢.
例:
$sample_json = @"
{
"fields": {
"field_one": 1,
"field_two": 2,
"field_three": "three",
"field_four": "remove_me",
"field_five": 5
}
}
"@
Clear-Host
$json_object = ConvertFrom-Json -InputObject $sample_json
$json_object
Run Code Online (Sandbox Code Playgroud)
得到:
fields
------
@{field_one=1; field_two=2; field_three=three; field_four=remove_me; field_five=5}
Run Code Online (Sandbox Code Playgroud)
所以问题是如何从$ json_object中删除"field_four"键及其值?抱歉,如果这很简单; 这几年我与Powershell有点脱节.
我是 Terraform 的新手,仍在研究文档,尚未找到一种方法来适应我需要实现的特定解决方案的设置,并希望某种灵魂能够能够推动我朝正确的方向前进。
我正在尝试管理一组参数化模板,这些模板部署支持我们在 GCP 中开发的新应用程序所需的一切。我想要实现的目标是能够将这些模板部署到三个不同的环境,每个环境本身都位于不同的 GCP 项目中。
根据建议,该计划是运行 terraform 并传入
a) 特定的 .tfvars 文件取决于部署到的环境/项目 (dev/test/prod)。
b) 使用 -chdir 参数告诉 Terraform 从“infra-common”文件夹中获取所有模板。
棘手的部分是我们希望每个环境(gcp 项目)在 gcs/storage 中托管它自己的状态文件。
我一直在研究工作区,但工作区似乎只会在单个后端上创建状态子文件夹。
问题:可以这样做或者有更好的方法吗?
谢谢!
我有一个int64喜欢:
1502712864232
这是REST GET到服务的结果.我可以很容易地将它转换为字符串.这是一个Unixnano时间戳.
我真正需要的是将它转换为与"欧洲/伦敦"时区相关的字符串.如:-
"2017年8月14日,13:14:24"
例如由这个方便的实用程序生成:http: //www.freeformatter.com/epoch-timestamp-to-date-converter.html
非常感谢任何帮助.
==>更新.
感谢@evanmcdonnal提供了这样一个有用的答案.非常感激.事实证明,我所拥有的数据根本不是UnixNano(对不起),距离Epoch只有几毫秒.来源是詹金斯的时间戳....
所以...我编写了以下帮助函数来获得我需要的东西:
// Arg 1 is an int64 representing the millis since Epoch
// Arg 2 is a timezome. Eg: "Europe/London"
// Arg 3 is an int relating to the formatting of the returned string
// Needs the time package. Obviously.
func getFormattedTimeFromEpochMillis(z int64, zone string, style int) string {
var x string
secondsSinceEpoch := z / 1000
unixTime := time.Unix(secondsSinceEpoch, 0)
timeZoneLocation, err := time.LoadLocation(zone) …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置一个简单的 Flask 应用程序,它使用 React 和 Material UI(我不能为此使用 Node/NPM)。React、react-dom 和 Material-ui.js 都由 Flask 从静态资源路径中提供服务。它们加载得很好,但在第一个 text/babel 函数中找不到 Button 元素。它位于material-ui.js 中,但我的JSX 函数看不到它。有没有办法从material-ui.js导入组件?
我的index.html:
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->
<head>
<!-- Metas -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" />
<title>F.L.O.P.</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Fonts --> …Run Code Online (Sandbox Code Playgroud) json ×2
jsonpath ×2
powershell ×2
terraform ×2
azure ×1
babeljs ×1
go ×1
google-iam ×1
gson ×1
java ×1
material-ui ×1
reactjs ×1
string ×1
time ×1