[英]Remove curly brackets from JObject
I receive a text which I parse as a JObject我收到一个文本,我将其解析为 JObject
txt = {"welcome":["Hello friend."],"image":"Y","IDs":{}}
var object = JObject.Parse(txt);
Among the values inside there is one called IDs which sometimes is empty.在内部的值中,有一个称为 ID 的值,有时为空。 I get the value by
我得到的价值
var mainID = object["IDs"].ToString();
And then I insert the value in a table.然后我将值插入表中。 The problem is that when the value is empty it return with {}.
问题在于,当值为空时,它会以 {} 返回。 So the insert statement fails.
所以插入语句失败。 How can I remove the curly brackets when the value is empty?
当值为空时如何删除大括号?
Update based on comment根据评论更新
You could use the following你可以使用以下
var mainID = (jobj["IDs"] is JValue)?(string)jobj["IDs"]:defaultValue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.