Bring JSON result in div with jquery

Asked

Viewed 226 times

3

I have the following JSON generated by the system:

var skuJson = {
  "productId": 17234,
  "name": "Sabonete AnaSuil Porta Joias Rose Bulgarie",
  "salesChannel": "1",
  "available": true,
  "displayMode": "especificacao",
  "dimensions": [
   "Volume"
  ],
  "dimensionsInputType": {
    "Volume": "Combo"
  },
  "dimensionsMap": {
"Volume": [
  "130 g"
]
  },
  "skus": [
{
  "sku": 17235,
  "skuname": "130 g + Grátis Toalha Fitness Club",
  "dimensions": {
    "Volume": "130 g"
  },
  "available": true,
  "listPriceFormated": "R$ 125,50",
  "listPrice": 12550,
  "bestPriceFormated": "R$ 95,38",
  "bestPrice": 9538,
  "installments": 4,
  "installmentsValue": 2384,
  "installmentsInsterestRate": 0,
  "image": "http://develop-shopluxo.vtexcommercebeta.com.br/arquivos/ids/169135-292-292/Sabonete-AnaSuil-Porta-Joias-Rose-Bulgarie.jpg?v=634868637715300000",
  "sellerId": "1",
  "seller": "shopluxo",
  "measures": {
    "cubicweight": 0.2083,
    "height": 10.0000,
    "length": 10.0000,
    "weight": 63.0000,
    "width": 10.0000
  },
  "rewardValue": 0
}
  ]
     };CATALOG_SDK.setProductWithVariationsCache(skuJson.productId,
skuJson);

I need to bring only the value of "skus": "sku": 17235 in a div with jQuery. What would be the way?

Note: the values above are in head within a script.

1 answer

3


The value of "sku" can be obtained as follows:

skuJson.skus[0].sku

The content of div can be defined with jQuery as follows:

$('#ID-da-div').text(skuJson.skus[0].sku);
  • 1

    Thank you very much Dang

  • If I use ajax it is necessary to transform into object with $.parseJSON?

  • What do you mean? Ajax is what you use to catch this object skuJson, which is already in object form, certain? parseJSON serves to transform a string into an object like the one you exemplified. More details in the documentation (in English): http://api.jquery.com/jquery.parsejson/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.