Archived Forum Post

Index of archived forum posts

Question:

LIST OF OBJECTS

Oct 07 '17 at 06:33

Hi, I need creat a list of objects like the structure below (link reference: https://github.com/buscape-company/api-ofertas)

[
    {
        "groupId": "",
        "sku": "",
        "title": "",
        "barcode": "",
        "category": "",
        "description": "",
        "images": [
            "url1",
            "url..."
        ],
        "isbn": "",
        "link": "",
        "linkLomadee": "",
        "prices": [
            {
                "type": "",
                "price": 0,
                "priceLomadee": 0,
                "priceCpa": 0,
                "installment": 0,
                "installmentValue": 0
            }
        ],
        "productAttributes": {
            "Atributo 1": "Valor 1",
            "Atributo ...": "Valor ..."
        },
        "technicalSpecification": {
            "Especificação 1": "Valor",
            "Especificação ...": "Valor ..."
        },
        "quantity": 0,
        "sizeHeight": 0,
        "sizeLength": 0,
        "sizeWidth": 0,
        "weightValue": 0,
        "declaredPrice": 0,
        "handlingTimeDays": 0,
        "marketplace": false,
        "marketplaceName": ""
    }
]
I tried with the commands below, but didn't work. Anyone could help me?
loJson.UpdateString('[0].sku','008100')
loJson.UpdateString('[0].title','RODA ESPORTIVA PRETA (MODELO CG 2014) FAN 125 2009/13 KS (TAMBOR) ACOMPANHA ROLAMENTOS FABRECK')
loJson.UpdateString('[0].category','Peças para motos')
loJson.UpdateString('[0].description','RODA ESPORTIVA PRETA (MODELO CG 2014) FAN 125 2009/13 KS (TAMBOR) ACOMPANHA ROLAMENTOS FABRECK')
loJson.UpdateString('[0].images[0]','http://atlantamotos.com.br/imagens/produtos/0008100-1.jpg')
loJson.UpdateString('[0].link','http://www.atlantamotos.com.br/p/0008100')
loJson.UpdateString('[0].prices[0].type','cartao_avista')
loJson.UpdateString('[0].prices[0].price',100.00)
loJson.UpdateString('[0].prices[0].type','cartao_avista')
loJson.UpdateString('[0].prices[0].installmentValue',20.00)
loJson.UpdateString('[0].prices[0].installment',6)
loJson.UpdateString('[0].technicalSpecification','MODELO CG 2104')
loJson.UpdateString('[0].quantity',100)
loJson.UpdateString('[0].sizeHeight',10)
loJson.UpdateString('[0].sizeLenght',10)
loJson.UpdateString('[0].sizeWidth',10)
loJson.UpdateString('[0].weightValue',0.500)
{"":[{"sku":"008100","title":"RODA ESPORTIVA PRETA (MODELO CG 2014) FAN 125 2009/13 KS (TAMBOR) ACOMPANHA ROLAMENTOS FABRECK","category":"Peças para motos","description":"RODA ESPORTIVA PRETA (MODELO CG 2014) FAN 125 2009/13 KS (TAMBOR) ACOMPANHA ROLAMENTOS FABRECK","images":["http://atlantamotos.com.br/imagens/produtos/0008100-1.jpg"],"link":"http://www.atlantamotos.com.br/p/0008100","prices":[{"type":"cartao_avista","price":"100","installmentValue":"20","installment":"6"}],"technicalSpecification":"MODELO CG 2104","quantity":"100","sizeHeight":"10","sizeLenght":"10","sizeWidth":"10","weightValue":"0,5"}]}

[{"errors":[{"code":"14","message":"Atributo sku inválido. O atributo é obrigatório e tamanha máx. 240 caracteres."},{"code":"8","message":"Atributo title inválido. O atributo é obrigatório, tamanho máx. 240 caracteres e tamanho min. 4 caracteres."},{"code":"15","message":"Atributo category inválido. O atributo é obrigatório e tamanho máx. 255 caracteres."},{"code":"10","message":"Necessário informar pelo menos uma imagem no atributo images."},{"code":"4","message":"Atributo link inválido. O atributo é obrigatório, precisa ser um link válido, tamanho máx. 4094 caracteres e sem espaços em branco."},{"code":"30","message":"Necessário informar pelo menos um preço no atributo prices."},{"code":"25","message":"Atributo quantity inválido. O atributo tem que ser um número inteiro, igual ou maior que 0."},{"code":"31","message":"Atributo sizeHeight está inválido. É obrigatório, deve ser numérico e maior que 0."},{"code":"32","message":"Atributo sizeLength está inválido. É obrigatório, deve ser numérico e maior que 0."},{"code":"33","message":"Atributo sizeWidth está inválido. É obrigatório, deve ser numérico e maior que 0."},{"code":"34","message":"Atributo weightValue está inválido. É obrigatório, deve ser numérico e maior que 0."}]}]


Answer

Go to http://tools.chilkat.io and copy-and-paste the object part of the JSON into the form for generating code to create JSON.

For example, copy-and-paste the following into the form:

    {
        "groupId": "",
        "sku": "",
        "title": "",
        "barcode": "",
        "category": "",
        "description": "",
        "images": [
            "url1",
            "url..."
        ],
        "isbn": "",
        "link": "",
        "linkLomadee": "",
        "prices": [
            {
                "type": "",
                "price": 0,
                "priceLomadee": 0,
                "priceCpa": 0,
                "installment": 0,
                "installmentValue": 0
            }
        ],
        "productAttributes": {
            "Atributo 1": "Valor 1",
            "Atributo ...": "Valor ..."
        },
        "technicalSpecification": {
            "Especificação 1": "Valor",
            "Especificação ...": "Valor ..."
        },
        "quantity": 0,
        "sizeHeight": 0,
        "sizeLength": 0,
        "sizeWidth": 0,
        "weightValue": 0,
        "declaredPrice": 0,
        "handlingTimeDays": 0,
        "marketplace": false,
        "marketplaceName": ""
    }

Then modify the resulting code to put it in a JSON array like this:

LOCAL loJArray
LOCAL loJson

loJArray = CreateObject('Chilkat_9_5_0.JsonArray')
loJArray.AddObjectAt(0)
loJson = loJArray.ObjectAt(0)

loJson.UpdateString("groupId","")
loJson.UpdateString("sku","")
loJson.UpdateString("title","")
loJson.UpdateString("barcode","")
loJson.UpdateString("category","")
loJson.UpdateString("description","")
loJson.UpdateString("images[0]","url1")
loJson.UpdateString("images[1]","url...")
loJson.UpdateString("isbn","")
loJson.UpdateString("link","")
loJson.UpdateString("linkLomadee","")
loJson.UpdateString("prices[0].type","")
loJson.UpdateNumber("prices[0].price","0")
loJson.UpdateNumber("prices[0].priceLomadee","0")
loJson.UpdateNumber("prices[0].priceCpa","0")
loJson.UpdateNumber("prices[0].installment","0")
loJson.UpdateNumber("prices[0].installmentValue","0")
loJson.UpdateString('productAttributes."Atributo 1"',"Valor 1")
loJson.UpdateString('productAttributes."Atributo ..."',"Valor ...")
loJson.UpdateString('technicalSpecification."Especificação 1"',"Valor")
loJson.UpdateString('technicalSpecification."Especificação ..."',"Valor ...")
loJson.UpdateNumber("quantity","0")
loJson.UpdateNumber("sizeHeight","0")
loJson.UpdateNumber("sizeLength","0")
loJson.UpdateNumber("sizeWidth","0")
loJson.UpdateNumber("weightValue","0")
loJson.UpdateNumber("declaredPrice","0")
loJson.UpdateNumber("handlingTimeDays","0")
loJson.UpdateBool("marketplace",0)
loJson.UpdateString("marketplaceName","")

loJArray.EmitCompact = 0
? loJArray.Emit()

RELEASE loJArray

Answer

The problem is that these structure is a list of objects. Each content between the "[]" are one object like this reference https://github.com/buscape-company/api-ofertas

In the truth I need build a object like this structure below (pay attention on "[]" before/begin and after/final of structure):

[ { "groupId": "", "sku": "", "title": "", "barcode": "", "category": "", "description": "", "images": [ "url1", "url..." ], "isbn": "", "link": "", "linkLomadee": "", "prices": [ { "type": "", "price": 0, "priceLomadee": 0, "priceCpa": 0, "installment": 0, "installmentValue": 0 } ], "productAttributes": { "Atributo 1": "Valor 1", "Atributo ...": "Valor ..." }, "technicalSpecification": { "Especificação 1": "Valor", "Especificação ...": "Valor ..." }, "quantity": 0, "sizeHeight": 0, "sizeLength": 0, "sizeWidth": 0, "weightValue": 0, "declaredPrice": 0, "handlingTimeDays": 0, "marketplace": false, "marketplaceName": "" } ]