必须在Json的键中输入值,但我无法实现,我该怎么做?
示例:
{
"name": "Allan",
"lastname": "Zé Store",
"type": "J",
"street": "Rua Abdon Batista, 121",
"emails": [
{
"email": "jose@zestore.com.br"
},
{
"email": "marcos@zestore.com.br"
}
],
"phone": [
{
"number": "(11) 98765-4321"
},
{
"number": "(47) 9876-5432"
}
]
}
我需要在密钥内组装一个数组吗?
答案 0 :(得分:1)
我认为你需要的是为所需的键定义一个对象数组。我希望这段代码可以帮到你:
private void test()
{
ojson myjson = new ojson();
List<Email> myemails=new List<Email>();
Email email = new Email();
email.email = "";
Email email2 = new Email();
email2.email = "";
myemails.Add(email);
myemails.Add(email2);
myjson.emails = myemails;
}
public class Email
{
public string email { get; set; }
}
public class Phone
{
public string number { get; set; }
}
public class ojson
{
public string name { get; set; }
public string lastname { get; set; }
public string type { get; set; }
public string street { get; set; }
public List<Email> emails { get; set; }
public List<Phone> phone { get; set; }
}