有没有一种方法可以从某种类型的JSON.NET JObject中删除节点? [英] Is there a way to remove nodes from JSON.NET JObject of a certain type?

查看:408
本文介绍了有没有一种方法可以从某种类型的JSON.NET JObject中删除节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从API返回的JSON对象,其中一些节点是数组.我有什么办法可以完全根据类型"将其从对象中拉出吗?

I've got a JSON object that's returned from an API and some of the nodes are arrays. Is there any way for me to pull those out of the object completely based on the "type" ?

例如:

{ "result" : {
"field1": "value1",
"field2" : [ "val2", "val3" ],
"field3" : "val4",
"field4" : "val5" }
}

我希望能够删除"field2",因为它是一个数组.

I'd like to be able to remove "field2" because it's an array.

我不确定如何以一种可以让我知道对象类型的方式遍历对象.

i'm not sure how to iterate through the object in a way that will give me the type of the object.

我正在使用C#和JSON.NET 6.0.5

I'm using C# and JSON.NET 6.0.5

谢谢!

推荐答案

解析数据后,请执行以下操作:

After you parse the data do this:

jsonObject.Property("field2").Remove();

这篇关于有没有一种方法可以从某种类型的JSON.NET JObject中删除节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆