检查JSON响应字段是否为空

时间:2017-02-16 14:29:12

标签: c# json parsing

我正在从Facebook检索用户字段,如下所示:

2 个答案:

答案 0 :(得分:3)

这是使用null conditional operator

的好地方
if (myInfo.education[0]?.concentration[0]?.name != null)

如果education[0]concentration[0]为空,则会跳过链的其余部分。

答案 1 :(得分:0)

我认为你在寻找的是

(myInfo.education [0]?。concentration [0]?。name!= null)

但我相信它只有在属性实际上在对象上时才会起作用,即json部分不会丢失。如果教育根本不在目标上,我认为这仍然会爆发。

我的意思是

{   “id”:“757111564344608”,   “教育”: [],   “图片”:{

可以正常工作,但

{   “id”:“757111564344608”,   “图片”:{

会抛出异常。可能采取进一步措施的唯一方法是

.sec{
    position: absolute;
    height: 50%;
    width: 100%;
    background-color: #009fb2;
    top: 75%;   
}
.title{
    position: absolute;
    height: 15%;
    width: 40%;
    background-color: red;
    top: 5%;
    left: 30%;
}
.img{

    position: relative;
    width: 16%;
    left: 42%;
    top: 28%;   
}

.secleft{
    position: absolute;
    height: 57%;
    width: 30%;
    background-color: #006672;
    top: 28%; 
    left: 7%;
    border-radius: 3px;
}

.txt{
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: red;
}

可能需要更改GetValue行,您可能必须遍历教育的属性才能找到“类型”