How to convert Nokogiri Document object into JSON

前端 未结 3 1328
走了就别回头了
走了就别回头了 2020-12-25 14:40

I have some parsed Nokogiri::XML::Document objects that I want to print as JSON.

I can go the route of making it a string, parsing it into a hash, with

3条回答
  •  粉色の甜心
    2020-12-25 14:52

    If you are trying to convert a SOAP request to REST, this one works too:

    require 'active_support/core_ext/hash'
    require 'nokogiri'
    
    xml_string = "b"
    doc = Nokogiri::XML(xml_string)
    Hash.from_xml(doc.to_s)
    

提交回复
热议问题