JSONObject to Document

后端 未结 2 1185
滥情空心
滥情空心 2021-01-17 20:35

Hi there i am new with mongodb and i want to convert JSONObject to Document and then store it to mongodb. Here is what i have coded.I get a service api in json.

<         


        
相关标签:
2条回答
  • 2021-01-17 21:09

    Just to help you. You can also do:

    JSONObject rat = exRat.getJSONObject("fieldfromJson");String newrat = rat.toString();
    

    Then you have to parse the field you want, and you have a string.

    0 讨论(0)
  • 2021-01-17 21:13

    The MongoDB Java Driver provides the Document.parse(String json) method to get a Document instance from a JSON string. You will need to parse your JSON object back to a String like this:

    Document doc = Document.parse( Rat.toString() );
    

    And here's the docs for working with JSON in the MongoDB Java Driver.

    0 讨论(0)
提交回复
热议问题