JSONのnull
値をpostgresqlに保存しようとしています。私は次のコードを使用する場合:null値を持つAPIからJSONを保存する
resume = Resume.create!({
parsedres: {"Resume":{"xml:lang":"en","xmlns":"http://ns.hrxml.org/2006-02-28","xmlns:vos":"http://noresm.com/hr-xml/2006-02-28","ResumeId":{"IdValue":null}}}
})
を私はエラーを取得:
NameError: undefined local variable or method `null' for main:Object
問題は、私がnullのために "" なしAPIデータを取得し、私はJSON.parseを使用
resume.parsedres = JSON.parse(response.body)
resume.save
です
それは
JSON::ParserError: 765: unexpected token at '<ParseResumeResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Code>Ack</Code><SubCode>Authentication/SubCode><Message>AccountID.</Message><CreditsRemaining>100</CreditsRemaining></ParseResumeResponse>'
なぜスローJSON.parseは解釈しませんnull
?
JSONパーサーエラーは、XML応答を解析しようとしているようです。レスポンスボディを調べて、実際にJSON(JSONコンテンツを取得するためにリクエストにヘッダーを含める必要があるかもしれません)かどうかを確認してみます。 –
ありがとう、私は私のAPI呼び出しでJSONを要求しました。 resume.new レスポンス= RestClient :: Request.execute( メソッド:: post、 url: 'http:// APIの例'、 ペイロード:params、 **ヘッダー:{"Content-Type" = > "application/json"} ** ) – cruisertom
ヘッダーに 'Accept' => 'application/json'を含めることもできます。それでも問題が解決しない場合、APIがJSONをサポートしておらず、XMLだけをサポートしている可能性があります。 –