json-simple

How to find specified name and its value in JSON-string from Java? [closed]

北城以北 提交于 2019-11-28 08:56:48
Let's assume we have the next JSON string: { "name" : "John", "age" : "20", "address" : "some address", "someobject" : { "field" : "value" } } What is the easiest (but still correct, i.e. regular expressions are not acceptable) way to find field age and its value (or determine that there's no field with given name)? p.s. any open-source libs are ok. p.s.2: please, don't post links to the libraries - it's not a useful answer. 'Show me the code'(c). Use a JSON library to parse the string and retrieve the value. The following very basic example uses the built-in JSON parser from Android. String

Decoding JSON String in Java

淺唱寂寞╮ 提交于 2019-11-27 13:15:28
I am new to using the json-simple library in Java and I've been through both the encoding and decoding samples. Duplicating the encoding examples was fine, but I have not been able to get the decoding ones to work with mixed type JSON. One of my problems is that there are too many classes in the library which are not properly documented, and for which I do not have the source (in order to be able to read through and understand their purpose). Consequently, I am struggling to understand how to use a lot of these classes. After reading this example: String jsonText = "{\"first\": 123, \"second\"

How to find specified name and its value in JSON-string from Java? [closed]

十年热恋 提交于 2019-11-27 02:30:53
问题 Let's assume we have the next JSON string: { "name" : "John", "age" : "20", "address" : "some address", "someobject" : { "field" : "value" } } What is the easiest (but still correct, i.e. regular expressions are not acceptable) way to find field age and its value (or determine that there's no field with given name)? p.s. any open-source libs are ok. p.s.2: please, don't post links to the libraries - it's not a useful answer. 'Show me the code'(c). 回答1: Use a JSON library to parse the string

How to read json file into java with simple JSON library

≡放荡痞女 提交于 2019-11-26 15:00:49
I want to read this JSON file with java using json simple library. My JSON file looks like this: [ { "name":"John", "city":"Berlin", "cars":[ "audi", "bmw" ], "job":"Teacher" }, { "name":"Mark", "city":"Oslo", "cars":[ "VW", "Toyata" ], "job":"Doctor" } ] This is the java code I wrote to read this file: package javaapplication1; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Iterator; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser

Decoding JSON String in Java

感情迁移 提交于 2019-11-26 11:10:03
问题 I am new to using the json-simple library in Java and I\'ve been through both the encoding and decoding samples. Duplicating the encoding examples was fine, but I have not been able to get the decoding ones to work with mixed type JSON. One of my problems is that there are too many classes in the library which are not properly documented, and for which I do not have the source (in order to be able to read through and understand their purpose). Consequently, I am struggling to understand how

How to read json file into java with simple JSON library

孤街浪徒 提交于 2019-11-26 03:06:04
问题 I want to read this JSON file with java using json simple library. My JSON file looks like this: [ { \"name\":\"John\", \"city\":\"Berlin\", \"cars\":[ \"audi\", \"bmw\" ], \"job\":\"Teacher\" }, { \"name\":\"Mark\", \"city\":\"Oslo\", \"cars\":[ \"VW\", \"Toyata\" ], \"job\":\"Doctor\" } ] This is the java code I wrote to read this file: package javaapplication1; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Iterator; import org

Pretty-Print JSON in Java

左心房为你撑大大i 提交于 2019-11-26 00:31:14
I'm using json-simple and I need to pretty-print JSON data (make it more human readable). I haven't been able to find this functionality within that library. How is this commonly achieved? Ray Hulha GSON can do this in a nice way: Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonParser jp = new JsonParser(); JsonElement je = jp.parse(uglyJSONString); String prettyJsonString = gson.toJson(je); Raghu Kiran I used org.json built-in methods to pretty-print the data. JSONObject json = new JSONObject(jsonString); // Convert text to object System.out.println(json.toString(4)); // Print