2016-12-05 41 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"