【发布时间】:2014-07-07 12:37:25
【问题描述】:
我制作了一个 ASP.NET WEB API,它以 json 格式获取客户和营养的详细信息。我在 IIS 上部署了我的 API,它工作正常。现在我想在我的 MVC 项目上使用该 API 的 URL。我的 URL 是这样的“http:/localhost:12/customernutrient/customernutrient?o=json”和类是这样的
public class Header
{
public string api_ver { get; set; }
public int req_type { get; set; }
public int code { get; set; }
public string description { get; set; }
}
public class Customer
{
public int customerId { get; set; }
public string customerName { get; set; }
}
public class Nutrient
{
public int nutrientId { get; set; }
public string nutrientName { get; set;}
}
public class Body
{
public List<Customer> customer { get; set; }
public List<Nutrient> nutrient { get; set; }
}
public class RootObject
{
public Header header { get; set; }
public Body body { get; set; }
}
如何在我的链接的帮助下调用我的 API 并以标签之类的方式显示内容。我想在不同的标签中显示这些数据
{
"header": {
"api_ver": "1.2",
"req_type": 1,
"code": 1,
"description": "Successful output"
},
"body": {
"customer": [
{
"customerId": 1,
"customerName": "Roundys1"
},
{
"customerId": 2049,
"customerName": "Test"
}
],
"nutrient": [
{
"nutrientId": 1,
"nutrientName": "Calcium"
},
{
"nutrientId": 2,
"nutrientName": "Calories"
},
{
"nutrientId": 3,
"nutrientName": "Cholesterol"
},
{
"nutrientId": 4,
"nutrientName": "Dietary Fiber"
},
{
"nutrientId": 5,
"nutrientName": "Iron"
},
{
"nutrientId": 6,
"nutrientName": "Polyunsaturated Fat"
},
{
"nutrientId": 7,
"nutrientName": "Potassium"
},
{
"nutrientId": 8,
"nutrientName": "Protein"
},
{
"nutrientId": 9,
"nutrientName": "Saturated Fat"
},
{
"nutrientId": 10,
"nutrientName": "Sodium"
},
{
"nutrientId": 11,
"nutrientName": "Sugars"
},
{
"nutrientId": 12,
"nutrientName": "Total Carbohydrate"
},
{
"nutrientId": 13,
"nutrientName": "Total Fat"
},
{
"nutrientId": 14,
"nutrientName": "Vitamin A"
},
{
"nutrientId": 15,
"nutrientName": "Vitamin C"
}
]
}
}
请分享您可能的解决方案
【问题讨论】:
-
显示你到目前为止尝试过的内容。
-
我在 Web 表单中的 C# 代码的帮助下完成了这项工作,但我不知道如何在 Razor 中实现这一点
-
那么你希望有人在这个问题中用剃须刀引擎教你 MVC 吗?
标签: asp.net asp.net-mvc json