mirror of
https://github.com/nlohmann/json.git
synced 2026-10-13 01:47:11 +00:00
deploy: 40a62947d3
This commit is contained in:
1 parent
79119509a9
commit
22fba27145
555 files changed
+17342
-1394
No files matched your search
@@ -25,13 +25,39 @@ JSON Lines input with more than one value is treated as invalid JSON by the [`pa
|
||||
The example below demonstrates how JSON Lines can be processed.
|
||||
|
||||
```cpp
|
||||
--8<-- "examples/json_lines.cpp"
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
int main()
|
||||
{
|
||||
// JSON Lines (see https://jsonlines.org)
|
||||
std::stringstream input;
|
||||
input << R"({"name": "Gilbert", "wins": [["straight", "7♣"], ["one pair", "10♥"]]}
|
||||
{"name": "Alexa", "wins": [["two pair", "4♠"], ["two pair", "9♠"]]}
|
||||
{"name": "May", "wins": []}
|
||||
{"name": "Deloise", "wins": [["three of a kind", "5♣"]]}
|
||||
)";
|
||||
|
||||
std::string line;
|
||||
while (std::getline(input, line))
|
||||
{
|
||||
std::cout << json::parse(line) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
--8<-- "examples/json_lines.output"
|
||||
{"name":"Gilbert","wins":[["straight","7♣"],["one pair","10♥"]]}
|
||||
{"name":"Alexa","wins":[["two pair","4♠"],["two pair","9♠"]]}
|
||||
{"name":"May","wins":[]}
|
||||
{"name":"Deloise","wins":[["three of a kind","5♣"]]}
|
||||
|
||||
```
|
||||
|
||||
!!! warning "Note"
|
||||
|
||||
Reference in new issue
Block a user