比较两个JSON字符串,只需要更改的行

时间:2015-02-28 09:59:30

标签: ruby-on-rails ruby json ruby-on-rails-4

我在Ruby中面临有关JSON处理的问题。我有一个字符串str1,几分钟后它变为str2

str1 = 
'{   "Person1": { "state": [ {"salery": "100", "time": "100"} ],
                 "temp": [{"age": "12","time": "200" }] },
    "person2": { "state": [ {"salery": "12","time": "120"}],
                "temp": [ {"age": "12","time": "220"}]}
}'

更改为:

str1 = 
'{   
      "Person1": { "state": [ {"salery": "changed", "time": "100"} ],
                        "temp": [{"age": "12","time": "200" }] },
      "person2": { "state": [ {"salery": "12","time": "120"}],
                        "temp": [ {"age": "12","time": "220"}]}
}'

根据此更改,我只需要输出更改行,因为这里只有str1行 - > str2已更改({"salery": "100" -> "salery": "changed")

输出:

{
    "Person1": { "state": [ { "salery": "changed","time": "100"} ]  }
}

0 个答案:

没有答案