Create doğru şekilde JSON-nesne

0 Cevap php

Ben bir PHP dizi dışında bir JSON nesnesi oluşturmak için çalışıyorum. Dizi bu gibi görünüyor:

$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);

JSON kodlamak için kod şöyle:

$post_data = json_encode($post_data);

JSON dosya sonunda böyle bakmak gerekiyordu:

{
    "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
    }
} 

Nasıl ben "öğe" olarak oluşturulan JSON kodu kozalayabilirsiniz: {BURAYA JSON KOD}.

0 Cevap