Ruby on Railsでjsonを受け取り、それをxmlに変換して別APIにリクエストを送るプログラムを作っています
現状、受け取ったjsonは以下の方法でxmlに変換しております。
ruby
1xml_input=JSON.parse(request.body.read).to_xml
ですが、この方法で変換した場合、一番上に<hash>
がついてしまい、別APIへのリクエストにおいて障害が出てしまいます。
以下、sampleとして、jsonと変換後のxmlを記載いたします。
json
1{ 2 "title": "Person", 3 "type": "object", 4 "properties": { 5 "firstName": { 6 "type": "string" 7 }, 8 "lastName": { 9 "type": "string" 10 }, 11 "age": { 12 "description": "Age in years", 13 "type": "integer", 14 "minimum": 0 15 } 16 }, 17 "required": ["firstName", "lastName"] 18} 19
xml
1<?xml version="1.0" encoding="UTF-8" ?> 2<!--↓これをなくしたい--> 3<hash> 4<title>Person</title> 5<type>object</type> 6<properties> 7<firstName> 8<type>string</type> 9</firstName> 10<lastName> 11<type>string</type> 12</lastName> 13<age> 14<description>Age in years</description> 15<type>integer</type> 16<minimumtype="integer">0</minimum> 17</age> 18</properties> 19<requiredtype="array"> 20<required>firstName</required> 21<required>lastName</required> 22</required> 23</hash> 24<!--↑これをなくしたい-->
xml変換時点で、<hash>をつかないようにする もしくは xmlに変換した後に<hash>を取り除く 方法があればご教授いただきたいです。
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/09 13:56