【发布时间】:2020-03-09 06:44:55
【问题描述】:
我正在加载嵌套对象,但传入的数据没有正确关闭 json“[”: 有人可以帮忙吗,我无法检索数据。
[{"Id":1,"Barcode":"N001",.....,"ProductSubCategoryID":1,"SellerId":0,"SellerName":null,"ProductSubCategory":{"ProductSubCategoryID ":1,"SubCategoryName":"乳液","产品":["
public class Product
{
[Key]
public int Id { get; set; }
.
.
[ForeignKey("ProductSubCategoryID")]
public virtual ProductSubCategory ProductSubCategory { get; set; }
}
public class ProductSubCategory
{
[Key]
public int ProductSubCategoryID { get; set; }
[Required]
[Column(TypeName = "nvarchar(100)")]
public string SubCategoryName { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
// GET: api/Product
public async Task<Object> GetProducts()
{
return Ok(await _context.Products.Include(p => p.ProductSubCategory).ToListAsync());
}
readonly BaseURI = 'http://localhost:54277/api/Product';
private product$: Observable<Product[]>;
// Get All Products
getProducts(): Observable<Product[]> {
if (!this.product$) {
this.product$ = this.http.get < Product[] > (this.BaseURI + '/GetProducts').pipe(shareReplay());
}
return this.product$;
}
【问题讨论】:
-
您应该尝试打印数据。错误消息是说您的数据没有正确的 JSON 格式并且无法解析。您可以在这里验证您的输入:jsonlint.com
标签: c# asp.net angular asp.net-core-webapi typescript-typings