How do I store JSON data on a disk?

后端 未结 4 1330
日久生厌
日久生厌 2021-02-08 08:25

I am totally new to JSON and I might need to use it in the future so I did some reading bout it. There\'s lots of questions regarding JSON on SO. I found heaps of articles using

4条回答
  •  温柔的废话
    2021-02-08 09:07

    I guess the first thing to understand is that JSON is just one way of representing information. You can store the data however you like. If you have a relational database, you can probably come up with a reasonable way of converting the data back and forth.

    { 
      "id": 321
      "name" : "Jim",
      "age" : 27,
      "email" : "jim@jimsoft.com"
    }
    

    Might be represented in xml as

    
       321
       Jim
       27
       jim@jimsoft.com
    
    

    Or might be stored in the a table that looks like

    _______________________________________
    | id | name | age | email              |
    ========================================
    |321 | Jim  | 27  |jim@jimsoft.com     |
    ----------------------------------------
    

    So if you can store the information however you want. You just need some way to serialize/unserialize the data into whatever form you want.

    All that being said, If you need to store the JSON and storing it as a file won't work, You probably want to look at CouchDB or MongoDB. They are document-oriented databases that actually store JSON documents. They will let you store whatever JSON documents you want. You can build views and and query the data directly without having to convert the data to different forms.

提交回复
热议问题