2016-12-05 40 views
-2

我有下面的JSON響應,我想添加消息密鑰。我如何插入它。JSON中消息的Ruby額外密鑰

{ 

    "bundle_deals": [ 
    { 
     "id": 60, 
     "service_category_id": 5, 
     "service_provider_id": 12, 
     "title": "Voice + Internet", 
     "short_description": "Internet speeds up to 75Mbps.\r\nUnlimited calling", 

    } 

    ] 
} 

回答

1

您可以將JSON轉換爲散列,然後只需將一個鍵添加到散列。

require 'json' 
    hash = JSON.parse(value) 
    hash.message_key = "your message key"