Skip to content

Commit 63089c2

Browse files
author
vvedenin
committed
Add JsonSimple to json sections
1 parent 5932694 commit 63089c2

File tree

2 files changed

+95
-46
lines changed

2 files changed

+95
-46
lines changed

helloworlds/3.8-json/readme-russian.md

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@
6161
### 1.1 Обзор библиотек
6262

6363

64-
Способ | [Fastjson ](https://github.com/alibaba/fastjson)| [Gson](https://github.com/google/gson) | [LoganSquare](https://github.com/bluelinelabs/LoganSquare) | [JSON java](https://github.com/stleary/JSON-java) | [Moshi](https://github.com/square/moshi) | [Ig json parser](https://github.com/Instagram/ig-json-parser) | [Jackson](http://wiki.fasterxml.com/JacksonHome) | [Genson](http://owlike.github.io/genson/) | [JsonPath](https://github.com/jayway/JsonPath)
65-
---------- | --- | --- | --- | --- | --- | --- | --- | --- | ---
66-
1. Data bind | [Да ](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/fastjson)| [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/gson) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/logansquare) | - | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/moshi) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/ig_json_parser) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/jackson) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/genson) | -
67-
2. Tree Model | - | [Да ](https://github.com/Vedenin/useful-java-links/blob/master/helloworlds/3.8-json/gson/src/main/java/gson/advanced/TreeModel.java)| - | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/json_java) | - | - | [Да](https://github.com/Vedenin/useful-java-links/blob/master/helloworlds/3.8-json/jackson/src/main/java/jackson/advanced/TreeModel.java) | - | -
68-
3. Streaming API | - | [Да ](https://github.com/Vedenin/useful-java-links/blob/master/helloworlds/3.8-json/gson/src/main/java/gson/advanced/StreamingAPI.java)| - | - | - | - | [Да](https://github.com/Vedenin/useful-java-links/blob/master/helloworlds/3.8-json/jackson/src/main/java/jackson/advanced/StreamingAPI.java) | - | -
69-
4. Аналоги XPath | [Да](https://github.com/Vedenin/useful-java-links/blob/master/helloworlds/3.8-json/fastjson/src/main/java/fastjson/JsonPathHelloWorld.java) | - | - | - | - | - | [Да](https://github.com/Vedenin/useful-java-links/blob/master/helloworlds/3.8-json/jackson/src/main/java/jackson/advanced/JsonPointerHelloWorld.java) | - | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/json_path)
70-
5. Генерация классов для Data bind | - | - | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/logansquare) | - | - | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/ig_json_parser) | - | - | -
71-
6. Github's star | 4851 | 4120 | 2188 | 1937 | 1732 | 921 | 881 | 108 | 849
72-
7. Работает со static inner class | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/fastjson) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/gson) | [Нет](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/logansquare) | - | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/moshi) | [Нет](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/ig_json_parser) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/jackson) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/genson) | -
73-
8. Обязательность аннотаций | [Нет](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/fastjson) | [Нет](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/gson) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/logansquare) | - | [Нет](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/moshi) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/ig_json_parser) | [Нет](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/jackson) | [Нет](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/genson)| -
64+
Способ | [Fastjson ](https://github.com/alibaba/fastjson)| [Gson](https://github.com/google/gson) | [LoganSquare](https://github.com/bluelinelabs/LoganSquare) | [JSON java](https://github.com/stleary/JSON-java) | [Moshi](https://github.com/square/moshi) | [Ig json parser](https://github.com/Instagram/ig-json-parser) | [Jackson](http://wiki.fasterxml.com/JacksonHome) | [Genson](http://owlike.github.io/genson/) | [JsonPath](https://github.com/jayway/JsonPath) | [JSON.simple](https://github.com/fangyidong/json-simple)
65+
---------- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
66+
1. Data bind | [Да ](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/fastjson)| [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/gson) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/logansquare) | - | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/moshi) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/ig_json_parser) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/jackson) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/genson) | - | -
67+
2. Tree Model | - | [Да](https://github.com/Vedenin/useful-java-links/blob/master/helloworlds/3.8-json/gson/src/main/java/gson/advanced/TreeModel.java)| - | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/json_java) | - | - | [Да](https://github.com/Vedenin/useful-java-links/blob/master/helloworlds/3.8-json/jackson/src/main/java/jackson/advanced/TreeModel.java) | - | - | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/json_simple)
68+
3. Streaming API | - | [Да ](https://github.com/Vedenin/useful-java-links/blob/master/helloworlds/3.8-json/gson/src/main/java/gson/advanced/StreamingAPI.java)| - | - | - | - | [Да](https://github.com/Vedenin/useful-java-links/blob/master/helloworlds/3.8-json/jackson/src/main/java/jackson/advanced/StreamingAPI.java) | - | - | -
69+
4. Аналоги XPath | [Да](https://github.com/Vedenin/useful-java-links/blob/master/helloworlds/3.8-json/fastjson/src/main/java/fastjson/JsonPathHelloWorld.java) | - | - | - | - | - | [Да](https://github.com/Vedenin/useful-java-links/blob/master/helloworlds/3.8-json/jackson/src/main/java/jackson/advanced/JsonPointerHelloWorld.java) | - | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/json_path) | -
70+
5. Генерация классов для Data bind | - | - | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/logansquare) | - | - | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/ig_json_parser) | - | - | - | -
71+
6. Github's star | 4851 | 4120 | 2188 | 1937 | 1732 | 921 | 881 | 108 | 849 | 161
72+
7. Работает со static inner class | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/fastjson) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/gson) | [Нет](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/logansquare) | - | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/moshi) | [Нет](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/ig_json_parser) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/jackson) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/genson) | - | -
73+
8. Обязательность аннотаций | [Нет](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/fastjson) | [Нет](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/gson) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/logansquare) | - | [Нет](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/moshi) | [Да](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/ig_json_parser) | [Нет](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/jackson) | [Нет](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/genson)| - | -
7474

7575
По ссылкам на **Да** можно найти примеры использования.
7676

@@ -272,22 +272,22 @@ jsonString =
272272

273273
Методы парсинга json'a:
274274
275-
Действие | [Gson](https://github.com/google/gson) | [Jackson](http://wiki.fasterxml.com/JacksonHome) | [JSON java](https://github.com/stleary/JSON-java)
276-
---------- | --- | --- | ---
277-
Инициализация| `JsonParser parser = new JsonParser()` | `new ObjectMapper()` | -
278-
Парсинг json'a | `parser.parse(<строка>)` | `mapper.readValue(<строка>, JsonNode.class)` | `new JSONObject(<строка>)`
279-
Получение главного объекта | `root.getAsJsonObject()` | - | -
280-
Получение строки | `root.get(<имя>).getAsString()` | `root.get(<имя>).asText()` | `root.getString(<имя>)`
281-
Получение дочернего объекта | `root.getAsJsonObject(<имя>)` | `root.get(<имя>)` | `root.getJSONObject(<имя>)`
275+
Действие | [Gson](https://github.com/google/gson) | [Jackson](http://wiki.fasterxml.com/JacksonHome) | [JSON java](https://github.com/stleary/JSON-java) | [JSON.simple](https://github.com/fangyidong/json-simple) |
276+
---------- | --- | --- | --- | ---
277+
Инициализация| `JsonParser parser = new JsonParser()` | `new ObjectMapper()` | - | -
278+
Парсинг json'a | `parser.parse(<строка>)` | `mapper.readValue(<строка>, JsonNode.class)` | `new JSONObject(<строка>)` | `(JSONObject) JSONValue.parse(<строка>)`
279+
Получение главного объекта | `root.getAsJsonObject()` | - | - | -
280+
Получение строки | `root.get(<имя>).getAsString()` | `root.get(<имя>).asText()` | `root.getString(<имя>)` | `(String) root.get(<имя>)`
281+
Получение дочернего объекта | `root.getAsJsonObject(<имя>)` | `root.get(<имя>)` | `root.getJSONObject(<имя>)` | `(JSONObject) root.get(<имя>)`
282282

283283
Методы генерации json'a:
284284
285-
Действие | [Gson](https://github.com/google/gson) | [Jackson](http://wiki.fasterxml.com/JacksonHome) | [JSON java](https://github.com/stleary/JSON-java)
286-
---------- | --- | --- | ---
287-
Инициализация| - | `new ObjectMapper()` | -
288-
Создание главного объекта| `new JsonObject()` | `mapper.createObjectNode()` | `new JSONObject()`
289-
Добавить строковое поле | `root.addProperty(<имя>, <строка>)` | `root.put(<имя>, <строка>)` | `root.put(<имя>, <строка>)`
290-
Добавить дочерний объект | `root.add(<имя>, <объект>);` | `root.putObject(<имя>)` | `root.put(<имя>, <объект>)`
285+
Действие | [Gson](https://github.com/google/gson) | [Jackson](http://wiki.fasterxml.com/JacksonHome) | [JSON java](https://github.com/stleary/JSON-java) | [JSON.simple](https://github.com/fangyidong/json-simple)
286+
---------- | --- | --- | --- | ---
287+
Инициализация| - | `new ObjectMapper()` | - | -
288+
Создание главного объекта| `new JsonObject()` | `mapper.createObjectNode()` | `new JSONObject()` | `new JSONObject()`
289+
Добавить строковое поле | `root.addProperty(<имя>, <строка>)` | `root.put(<имя>, <строка>)` | `root.put(<имя>, <строка>)` | `root.put(<имя>, <строка>)`
290+
Добавить дочерний объект | `root.add(<имя>, <объект>);` | `root.putObject(<имя>)` | `root.put(<имя>, <объект>)` | `root.put(<имя>, <объект>)`
291291
292292
293293
Примеры:
@@ -372,6 +372,30 @@ jsonString =
372372
```
373373
[Подробный пример](https://github.com/Vedenin/useful-java-links/tree/master/helloworlds/3.8-json/json_java)
374374
375+
6) Чтение JSON.simple
376+
377+
```java
378+
JSONObject obj = (JSONObject) JSONValue.parse(json);
379+
String message = (String) obj.get("message");
380+
place = (JSONObject) obj.get("place");
381+
String name = (String) place.get("name");
382+
System.out.println(message + " " + name);
383+
```
384+
[Подробный пример](https://github.com/Vedenin/useful-java-links/blob/master/helloworlds/3.8-json/json_simple/src/main/java/json_simple/JsonSimpleHelloWorld.java)
385+
386+
7) Генерация JSON.simple
387+
388+
```java
389+
JSONObject root = new JSONObject();
390+
root.put("message", "Hi");
391+
JSONObject place = new JSONObject();
392+
place.put("name", "World!");
393+
root.put("place", place);
394+
String json = root.toJSONString();
395+
System.out.println(json);
396+
```
397+
[Подробный пример](https://github.com/Vedenin/useful-java-links/blob/master/helloworlds/3.8-json/json_simple/src/main/java/json_simple/JsonSimpleHelloWorld.java)
398+
375399
376400
В общем, можно заметить что во всех библиотеках выполняются примерно те же действия, отличаются только названия классов.
377401

0 commit comments

Comments
 (0)