我有一个需要反序列化的大型json数据集.我正在使用Json.net JsonTextReader来读取数据.
我的问题是我需要反序列化一些派生类,所以我需要能够"向前看"定义我的数据类型的特定属性.在下面的示例中,"type"参数用于确定要反序列化的对象类型.
{
type: "groupData",
groupParam: "groupValue1",
nestedObject:
{
type: "groupData",
groupParam: "groupValue2",
nestedObject:
{
type: "bigData",
arrayData: [ ... ]
}
}
Run Code Online (Sandbox Code Playgroud)
我的派生对象可以大量嵌套并且非常深.不希望将整个数据集加载到内存中,因为它需要大量内存.一旦我开始使用"bigData"对象,我将处理数据(例如上面示例中的数组),但它不会存储在内存中(它太大了).
到目前为止,我所看到的所有问题解决方案都用于JObject反序列化部分对象.我想避免使用,JObject因为它会反复地反序列化层次结构中的每个对象.
如何解决反序列化问题?
有没有办法提前搜索"type"参数,然后回溯到对象的{字符开始处理?
使用YamlDotNet,我试图反序列化以下YAML:
Collection:
- Type: TypeA
TypeAProperty: value1
- Type: TypeB
TypeBProperty: value2
Run Code Online (Sandbox Code Playgroud)
该Type属性是所有对象的必需属性Collection.其余属性取决于类型.
这是我理想的对象模型:
public class Document
{
public IEnumerable<IBaseObject> Collection { get; set; }
}
public interface IBaseObject
{
public string Type { get; }
}
public class TypeAClass : IBaseObject
{
public string Type { get; set; }
public string TypeAProperty { get; set; }
}
public class TypeBClass : IBaseObject
{
public string Type { get; set; }
public string TypeBProperty …Run Code Online (Sandbox Code Playgroud) 我curl用来连接REST API.REST API在Authorization标头中使用Bearer令牌.所以我的curl电话看起来像这样:
curl -H "Authorization: Bearer <token>" https://www.example.com/api
Run Code Online (Sandbox Code Playgroud)
此API已开始返回302重定向以响应我的API调用.
我添加了-L指示curl遵循重定向的选项:
curl -L -H "Authorization: Bearer <token>" https://www.example.com/api
Run Code Online (Sandbox Code Playgroud)
现在curl确实执行重定向.
这是问题所在:curl正在发送自定义Authorization标头以及重定向.我已经使用该-v选项对此进行了验证,因此它向我显示了它正在发送的标头.
新的服务器(我认为是Windows Azure)实际上使用400状态代码失败,因为它不喜欢Authorization标头.重定向的URL根本不需要授权标头.
那么,我怎样才能在重定向上curl不发送我的自定义Authorization标题?或者是否有另一种方法来指定Authorization避免问题的标题.
我正在尝试将 CloudWatch 操作限制为某个 VPC 或资源。我可以这样做吗?。以下是政策
{
"Sid": "AllowCloudWatchActions",
"Effect": "Allow",
"Action": [
"cloudwatch:DescribeAlarms",
"cloudwatch:GetMetricStatistics"
],
"Resource": "*"
}
Run Code Online (Sandbox Code Playgroud)
我可以为此指定任何条件吗?
我想根据特定json参数的值将请求路由到不同的操作.
例如,给定以下json数据:
{
type: "type1",
type1data: "type1value"
}
Run Code Online (Sandbox Code Playgroud)
和
{
type: "type2",
type2data: "type2value"
}
Run Code Online (Sandbox Code Playgroud)
我希望能在我的ApiController上有两个不同的动作:
void CreateType1(string type1data)
{
// ...
}
void CreateType2(string type2data)
{
//...
}
Run Code Online (Sandbox Code Playgroud)
这样的事情怎么办?
更新:
如果可能,我想要相同的网址.有点像/objects/create.
我正在使用 Microsoft Azure 的 C# SDK 来停止(解除分配)虚拟机。我正在尝试使用Microsoft.Azure.Management.Compute.Fluent.IVirtualMachine.Deallocate或 Microsoft.Azure.Management.Compute.IVirtualMachine.DeallocateWithHttpMessagesAsync。两者似乎都在等待虚拟机完成解除分配过程。
我想在不阻塞的情况下解除分配虚拟机以等待解除分配完成。
我注意到 Azure CLI 文档中有一个--no-wait选项。
来源:https : //docs.microsoft.com/en-us/cli/azure/vm?view=azure-cli-latest#az_vm_deallocate
如何使用适用于 Azure 的 C# SDK 实现这一点?