0

我正在使用 ShopifySharp,并从 Shopify 中提取产品数据。我遇到的问题BodyHtml是空的,即使它不在 JSON 响应中。

这是 Shopify 的响应,您可以看到body_html已设置:

{"title":"Adidas Originals Yeezy Boost 350 V2 Copper","body_html":"<p>Having truly created his own unique vision of contemporary sportswear, Kanye West returns with the eagerly-awaited Yeezy Season 3. Delivering a 3-fold release of the now iconic Yeezy Boost 350 V2 silhouette, each boasting a deep black Primeknit upper accompanied by either a copper, magenta pink or muted green accent. Continuing the idiosyncrasies of the V2 iteration, each sneaker will feature SPLY-350 interwoven to the side panel, sat atop an Adidas BOOST sole unit.</p>\n\n<ul>\n\t<li>Primeknit Uppers</li>\n\t<li>BOOST Sole Unit</li>\n\t<li>Ergonomic Sockliner</li>\n\t<li>SPLY-350 Branding</li>\n\t<li>Textured Outsole</li>\n\t<li>Style Code: BY1605</li>\n</ul>\n  <div class=\"size-and-fit-container\">\n<span class=\"size-and-fit-heading\">Size &amp; Fit</span>\n<div class=\"size-and-fit-content\">\n<p>This style fits small to size, therefore we advise you to take half a size up from your regular size. If you are usually in-between sizes, we recommend you to take a full size up.</p>\n</div>\n</div>","created_at":"2021-10-09T16:40:56+01:00","updated_at":"2021-10-09T16:40:59+01:00","published_at":"2021-10-09T16:40:56+01:00","vendor":"adidas","product_type":"","handle":"adidas-originals-yeezy-boost-350-v2-copper-by1605","template_suffix":null,"published_scope":"web","tags":"350, adidas, copper, kanye west, No Vat, yeezy, yeezy boost","status":"active","variants":[{"product_id":7172986994837,"title":"UK 7.5 | EU 41 1/3 | US 8","sku":"","position":1,"grams":0,"inventory_policy":"deny","fulfillment_service":"manual","inventory_item_id":43384586961045,"inventory_management":null,"price":799.99,"option1":"UK 7.5 | EU 41 1/3 | US 8","option2":null,"option3":null,"created_at":"2021-10-09T16:40:56+01:00","updated_at":"2021-10-09T16:40:56+01:00","taxable":true,"tax_code":null,"requires_shipping":true,"barcode":null,"inventory_quantity":0,"weight":0.0,"weight_unit":"lb","metafields":null,"presentment_prices":null,"id":41288961917077,"admin_graphql_api_id":"gid://shopify/ProductVariant/41288961917077"},{"product_id":7172986994837,"title":"UK 8 | EU 42 | US 8.5","sku":"BY1605.8UK","position":2,"grams":0,"inventory_policy":"deny","fulfillment_service":"manual","inventory_item_id":43384586993813,"inventory_management":null,"price":799.99,"option1":"UK 8 | EU 42 | US 8.5","option2":null,"option3":null,"created_at":"2021-10-09T16:40:56+01:00","updated_at":"2021-10-09T16:40:56+01:00","taxable":true,"tax_code":null,"requires_shipping":true,"barcode":null,"inventory_quantity":0,"weight":0.0,"weight_unit":"lb","metafields":null,"presentment_prices":null,"id":41288961949845,"admin_graphql_api_id":"gid://shopify/ProductVariant/41288961949845"},{"product_id":7172986994837,"title":"UK 10 | EU 44 2/3 | US 10.5","sku":"","position":3,"grams":0,"inventory_policy":"deny","fulfillment_service":"manual","inventory_item_id":43384587026581,"inventory_management":null,"price":799.99,"option1":"UK 10 | EU 44 2/3 | US 10.5","option2":null,"option3":null,"created_at":"2021-10-09T16:40:56+01:00","updated_at":"2021-10-09T16:40:56+01:00","taxable":true,"tax_code":null,"requires_shipping":true,"barcode":null,"inventory_quantity":0,"weight":0.0,"weight_unit":"lb","metafields":null,"presentment_prices":null,"id":41288961982613,"admin_graphql_api_id":"gid://shopify/ProductVariant/41288961982613"},{"product_id":7172986994837,"title":"UK 10.5 | EU 45 1/3 | US 11","sku":"BY1605.10.5UK","position":4,"grams":0,"inventory_policy":"deny","fulfillment_service":"manual","inventory_item_id":43384587059349,"inventory_management":null,"price":899.99,"option1":"UK 10.5 | EU 45 1/3 | US 11","option2":null,"option3":null,"created_at":"2021-10-09T16:40:56+01:00","updated_at":"2021-10-09T16:40:56+01:00","taxable":true,"tax_code":null,"requires_shipping":true,"barcode":null,"inventory_quantity":0,"weight":0.0,"weight_unit":"lb","metafields":null,"presentment_prices":null,"id":41288962015381,"admin_graphql_api_id":"gid://shopify/ProductVariant/41288962015381"}],"options":[{"product_id":7172986994837,"name":"Title","position":1,"values":["UK 7.5 | EU 41 1/3 | US 8","UK 8 | EU 42 | US 8.5","UK 10 | EU 44 2/3 | US 10.5","UK 10.5 | EU 45 1/3 | US 11"],"id":9262556872853,"admin_graphql_api_id":null}],"images":[{"product_id":7172986994837,"position":1,"created_at":"2021-10-09T16:40:58+01:00","updated_at":"2021-10-09T16:40:58+01:00","src":"https://cdn.shopify.com/s/files/1/0598/9869/1733/products/yeezy-boost-350-v2-cblack-coppmt-cblack-by1605_1.jpg?v=1633794058","attachment":null,"variant_ids":[],"height":1000,"width":1000,"alt":null,"metafields":null,"id":32581236129941,"admin_graphql_api_id":"gid://shopify/ProductImage/32581236129941"},{"product_id":7172986994837,"position":2,"created_at":"2021-10-09T16:40:58+01:00","updated_at":"2021-10-09T16:40:58+01:00","src":"https://cdn.shopify.com/s/files/1/0598/9869/1733/products/yeezy-boost-350-v2-cblack-coppmt-cblack-by1605_3.jpg?v=1633794058","attachment":null,"variant_ids":[],"height":1000,"width":1000,"alt":null,"metafields":null,"id":32581236162709,"admin_graphql_api_id":"gid://shopify/ProductImage/32581236162709"},{"product_id":7172986994837,"position":3,"created_at":"2021-10-09T16:40:58+01:00","updated_at":"2021-10-09T16:40:58+01:00","src":"https://cdn.shopify.com/s/files/1/0598/9869/1733/products/yeezy-boost-350-v2-cblack-coppmt-cblack-by1605_5.jpg?v=1633794058","attachment":null,"variant_ids":[],"height":1000,"width":1000,"alt":null,"metafields":null,"id":32581236195477,"admin_graphql_api_id":"gid://shopify/ProductImage/32581236195477"},{"product_id":7172986994837,"position":4,"created_at":"2021-10-09T16:40:58+01:00","updated_at":"2021-10-09T16:40:58+01:00","src":"https://cdn.shopify.com/s/files/1/0598/9869/1733/products/yeezy-boost-350-v2-cblack-coppmt-cblack-by1605_4.jpg?v=1633794058","attachment":null,"variant_ids":[],"height":1000,"width":1000,"alt":null,"metafields":null,"id":32581236228245,"admin_graphql_api_id":"gid://shopify/ProductImage/32581236228245"},{"product_id":7172986994837,"position":5,"created_at":"2021-10-09T16:40:59+01:00","updated_at":"2021-10-09T16:40:59+01:00","src":"https://cdn.shopify.com/s/files/1/0598/9869/1733/products/yeezy-boost-350-v2-cblack-coppmt-cblack-by1605_2.jpg?v=1633794059","attachment":null,"variant_ids":[],"height":1000,"width":1000,"alt":null,"metafields":null,"id":32581236326549,"admin_graphql_api_id":"gid://shopify/ProductImage/32581236326549"},{"product_id":7172986994837,"position":6,"created_at":"2021-10-09T16:40:59+01:00","updated_at":"2021-10-09T16:40:59+01:00","src":"https://cdn.shopify.com/s/files/1/0598/9869/1733/products/yeezy-boost-350-v2-cblack-coppmt-cblack-by1605_6.jpg?v=1633794059","attachment":null,"variant_ids":[],"height":1000,"width":1000,"alt":null,"metafields":null,"id":32581236392085,"admin_graphql_api_id":"gid://shopify/ProductImage/32581236392085"},{"product_id":7172986994837,"position":7,"created_at":"2021-10-09T16:40:59+01:00","updated_at":"2021-10-09T16:40:59+01:00","src":"https://cdn.shopify.com/s/files/1/0598/9869/1733/products/yeezy-boost-350-v2-cblack-coppmt-cblack-by1605_7.jpg?v=1633794059","attachment":null,"variant_ids":[],"height":1000,"width":1000,"alt":null,"metafields":null,"id":32581236261013,"admin_graphql_api_id":"gid://shopify/ProductImage/32581236261013"},{"product_id":7172986994837,"position":8,"created_at":"2021-10-09T16:40:59+01:00","updated_at":"2021-10-09T16:40:59+01:00","src":"https://cdn.shopify.com/s/files/1/0598/9869/1733/products/yeezy-boost-350-v2-cblack-coppmt-cblack-by1605_8.jpg?v=1633794059","attachment":null,"variant_ids":[],"height":1000,"width":1000,"alt":null,"metafields":null,"id":32581236424853,"admin_graphql_api_id":"gid://shopify/ProductImage/32581236424853"}],"metafields":null,"id":7172986994837,"admin_graphql_api_id":"gid://shopify/Product/7172986994837"}

但是在我的 Blazor 模板product.BodyHtml(即 a ShopifyProduct)中是空的。这是我的代码:

@page "/product/{id}"

@using System.Net.Http
@using System.Net.Http.Json
@using System.Threading.Tasks
@inject HttpClient Http

@if (isError)
{
    <p>Error loading product ...</p>
}
else if (product == null)
{
    <p>Loading Product ...</p>
}
else
{
    <h1>@product.Title</h1>

    <div class="variants">
        <select name="size">
            @foreach (ShopifySharp.ProductVariant variant in product.Variants)
        {
            <option value="@variant.Id">@variant.Title</option>
        }
        </select>
    </div>

    <button>Buy Now</button>
    <button>Add To Cart</button>

    <ul class="images">
        @foreach (ShopifySharp.ProductImage image in product.Images)
        {
            <li><img src="@image.Src" /></li>
        }
    </ul>

    <!-- TODO: This isn't printing anything, although body_html in the JSON response is present -->
    <p>@((MarkupString)product.BodyHtml)</p>
}

@code {
    [Parameter]
    public String Id { get; set; }
    private ShopifySharp.Product product;
    private bool isError;

    protected override async Task OnInitializedAsync()
    {
        try
        {
            product = await Http.GetFromJsonAsync<ShopifySharp.Product>(
                $"https://dc20211104185134.azurewebsites.net/api/Product?code=Ua8mVrXZJX9JpnlJw1AR5l8mersaCIIP6dRxAxIrwF0P/wS8Z298gA==&id={Id}"
        );
        }
        catch (Exception e)
        {
            isError = true;
        }
    }
}

知道这是为什么吗?

4

0 回答 0