Z
Z
Zzpro2022-02-11 13:36:31
PHP
Zzpro, 2022-02-11 13:36:31

What is wrong with generating json?

I update the balances on valberis by api I form an

array

$item_data = array(
            '0' => array(
                'barcode' => '656334e3564439',
                'stock' => '1',
                'warehouseId' => '7543'
            )
 $data = json_encode($item_data);


Gives an error Incorrect query scheme

If I form an array, everything works like that
$data = '[{"barcode":"656334e3564439","stock":1,"warehouseId":7543}]';


I don't understand what I'm doing wrong

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2022-02-11
@Zzpro

The string key 0 is not needed.
Or string values ​​where they should be numeric.
You need to look at the wildberries documentation.
But if you have an example of a working json, then it is formed like this:

$item_data = [
  [
    'barcode' => '656334e3564439',
    'stock' => 1,
    'warehouseId' => 7543,
  ]
];
$data = json_encode($item_data);

S
Stalker_RED, 2022-02-11
@Stalker_RED

[{"barcode":"656334e3564439","stock":"1","warehouseId":"7543"}]
[{"barcode":"656334e3564439","stock":1,"warehouseId":7543}]

difference in quotes?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question