Decode JSON data in Java

前端 未结 7 541
旧时难觅i
旧时难觅i 2020-12-03 15:20

I\'m used to PHP, and decoding json data is just a line of code. What would be the easiest way to do this in java?

相关标签:
7条回答
  • 2020-12-03 15:57

    have a look at http://code.google.com/p/json-simple/ maybe it helps ;-)

    0 讨论(0)
  • 2020-12-03 15:59

    Pick one of the libraries from the Java section at the bottom of the json.org page.

    0 讨论(0)
  • 2020-12-03 16:01

    Gson

    Userguide

    0 讨论(0)
  • 2020-12-03 16:01

    Decoding json in java is not too hard. Google's gson api handles json data very well. A tutorial on decoding json data using gson is there in my blog http://preciselyconcise.com/apis_and_installations/json_to_java.php

    0 讨论(0)
  • 2020-12-03 16:05

    I love Gson, it's very simple and easy to use. If you are interessted in more, here is a tutorial (german): http://blog.mynotiz.de/programmieren/java-json-decode-tutorial-2074/

    0 讨论(0)
  • 2020-12-03 16:14

    There are many JSON libraries available in Java.

    The most notorious ones are: Jackson, GSON, Genson, FastJson and org.json.

    There are typically three things one should look at for choosing any library:

    1. Performance
    2. Ease of use (code is simple to write and legible) - that goes with features.
    3. For mobile apps: dependency/jar size

    Specifically for JSON libraries (and any serialization/deserialization libs), databinding is also usually of interest as it removes the need of writing boiler-plate code to pack/unpack the data.

    For 1, see this benchmark: https://github.com/fabienrenaud/java-json-benchmark I did using JMH which compares (jackson, gson, genson, fastjson, org.json, jsonp) performance of serializers and deserializers using stream and databind APIs. For 2, you can find numerous examples on the Internet. The benchmark above can also be used as a source of examples...

    Quick takeaway of the benchmark: Jackson performs 5 to 6 times better than org.json and more than twice better than GSON.

    Let me know if you have any questions.

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