我遇到了同样的问题,发现剪贴板中应该有有效的 JSON 文本。
使其工作的步骤:
- 为您的 VS (Visual Studio) 版本安装 Web Essentials。Web Essentials 下载页面
- 在 VS 中创建空的类文件。
- 将有效的 JSON 文本复制到剪贴板。
- 您现在将在 Edit -> Paste Special -> Paste Json as Classes 下看到“Paste Json as Classes”
样本输入:
{
"firstName":"John",
"lastName":"Smith",
"age":25,
"address":{
"streetAddress":"21 2nd Street",
"city":"New York",
"state":"NY",
"postalCode":"10021"
},
"phoneNumber":[
{
"type":"home",
"number":"212 555-1234"
},
{
"type":"fax",
"number":"646 555-4567"
}
]
}
样本输出:
public class Rootobject
{
public string firstName { get; set; }
public string lastName { get; set; }
public int age { get; set; }
public Address address { get; set; }
public Phonenumber[] phoneNumber { get; set; }
}
public class Address
{
public string streetAddress { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postalCode { get; set; }
}
public class Phonenumber
{
public string type { get; set; }
public string number { get; set; }
}