Bir PHP dizisinden bir JSON nesnesi oluşturmaya çalışıyorum. Dizi şuna benzer:JSON nesnesini doğru şekilde oluştur
$post_data = array('item_type_id' => $item_type,
'string_key' => $string_key,
'string_value' => $string_value,
'string_extra' => $string_extra,
'is_public' => $public,
'is_public_for_contacts' => $public_contacts);
kodu şöyle JSON göz kodlamak için:
JSON dosyası sonunda şuna benzer gerekiyordu$post_data = json_encode($post_data);
:
{
"item": {
"is_public_for_contacts": false,
"string_extra": "100000583627394",
"string_value": "value",
"string_key": "key",
"is_public": true,
"item_type_id": 4,
"numeric_extra": 0
}
}
Oluşturulan JSON kodunu "item" bölümünde nasıl depolayabilirim: {JSON CODE HERE}.
i 'JSON_FORCE_OBJECT' eklersiniz json_encode içinde ($ arr, JSON_FORCE_OBJECT) ' –
Bu doğru mu? $ post_data = json_encode (dizi ('öğe' => $ post_data), JSON_FORCE_OBJECT); – user339067
Evet ... ama bunu test edebilir ve çalışıp çalışmadığını bize söyleyebilirsin;) – Cristian