我正在加载嵌套对象,但传入的数据没有正确关闭json“ [”: 有人可以帮忙,我无法检索数据。
[{“ Id”:1,“条形码”:“ 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$;
}