deploy: 4d46bce4e1
This commit is contained in:
1 parent
0c49bb37a5
commit
2aaa1d24ef
346 files changed
+1687
-1033
No files matched your search
@@ -1 +1 @@
|
||||
{"config":{"lang":["en"],"separator":"[\\s\\-\\.]","pipeline":["stopWordFilter"],"fields":{"title":{"boost":1000.0},"text":{"boost":1.0},"tags":{"boost":1000000.0}}},"docs":[{"location":"","title":"JSON for Modern C++","text":""},{"location":"api/json/","title":"nlohmann::json","text":"<pre><code>using json = basic_json<>;\n</code></pre> <p>This type is the default specialization of the basic_json class which uses the standard template types.</p>"},{"location":"api/json/#examples","title":"Examples","text":"Example <p>The example below demonstrates how to use the type <code>nlohmann::json</code>.</p> <pre><code>#include <iostream>\n#include <iomanip>\n#include <nlohmann/json.hpp>\n\nusing json = nlohmann::json;\n\nint main()\n{\n // create a JSON object\n json j =\n {\n {\"pi\", 3.141},\n {\"happy\", true},\n {\"name\", \"Niels\"},\n {\"nothing\", nullptr},\n {\n \"answer\", {\n {\"everything\", 42}\n }\n },\n {\"list\", {1, 0, 2}},\n {\n \"object\", {\n {\"currency\", \"USD\"},\n {\"value\", 42.99}\n }\n }\n };\n\n // add new values\n j[\"new\"][\"key\"][\"value\"] = {\"another\", \"list\"};\n\n // count elements\n auto s = j.size();\n j[\"size\"] = s;\n\n // pretty print with indent of 4 spaces\n std::cout << std::setw(4) << j << '\\n';\n}\n</code></pre> <p>Output:</p> <pre><code>{\n \"answer\": {\n \"everything\": 42\n },\n \"happy\": true,\n \"list\": [\n 1,\n 0,\n 2\n ],\n \"name\": \"Niels\",\n \"new\": {\n \"key\": {\n \"value\": [\n \"another\",\n \"list\"\n ]\n }\n },\n \"nothing\": null,\n \"object\": {\n \"currency\": \"USD\",\n \"value\": 42.99\n },\n \"pi\": 3.141,\n \"size\": 8\n}\n</code></pre>"},{"location":"api/json/#version-history","title":"Version history","text":"<p>Since version 1.0.0.</p>"},{"location":"api/operator_gtgt/","title":"nlohmann::operator>>(basic_json)","text":"<pre><code>std::istream& operator>>(std::istream& i, basic_json& j);\n</code></pre> <p>Deserializes an input stream to a JSON value.</p>"},{"location":"api/operator_gtgt/#parameters","title":"Parameters","text":"<code>i</code> (in, out) input stream to read a serialized JSON value from <code>j</code> (in, out) JSON value to write the deserialized input to"},{"location":"api/operator_gtgt/#return-value","title":"Return value","text":"<p>the stream <code>i</code></p>"},{"location":"api/operator_gtgt/#exceptions","title":"Exceptions","text":"<ul> <li>Throws <code>parse_error.101</code> in case of an unexpected token.</li> </ul>"},{"location":"api/operator_gtgt/#complexity","title":"Complexity","text":"<p>Linear in the length of the input. The parser is a predictive LL(1) parser.</p>"},{"location":"api/operator_gtgt/#notes","title":"Notes","text":"<p>A UTF-8 byte order mark is silently ignored.</p> <p>Invalid Unicode escapes and unpaired surrogates in the input are reported as <code>parse_error.101</code> with a detailed message.</p> <p><code>operator>></code> parses exactly one JSON value, so it can be called repeatedly to read a sequence of concatenated JSON values from the same stream:</p> <pre><code>json j1, j2;\ninput >> j1; // parses the first value\ninput >> j2; // parses the next value\n</code></pre> <p>A number must be followed by whitespace</p> <p>A number is only terminated by the character that follows it. That character is read from the stream to detect the end of the number, and it is not put back. When a value that is a number is immediately followed by the next value, the first character of that next value is lost:</p> <pre><code>std::istringstream input(\"1true\");\njson j1, j2;\ninput >> j1; // j1 == 1\ninput >> j2; // throws parse_error.101: the stream now starts at \"rue\"\n</code></pre> <p>Separating the values with whitespace avoids this, because the character that is eaten is then the separator:</p> <pre><code>std::istringstream input(\"1 true\");\njson j1, j2;\ninput >> j1; // j1 == 1\ninput >> j2; // j2 == true\n</code></pre> <p>Only numbers are affected. Values ending in a self-delimiting character do not read past themselves, so <code>truefalse</code>, <code>[1][2]</code>, <code>{\"a\":1}{\"b\":2}</code>, and <code>\"a\"\"b\"</code> can be read back to back without a separator.</p> <p>Define <code>JSON_PRECISE_STREAM_POSITION</code> to <code>1</code> to leave the terminating character in the stream instead, so that the stream is positioned right after the value for every value type and no separator is needed. This is tracked in #5340.</p> <p>Note that reading concatenated values does not work for JSON Lines (newline-delimited JSON) input -- see that page Line truncated
|
||||
{"config":{"lang":["en"],"separator":"[\\s\\-\\.]","pipeline":["stopWordFilter"],"fields":{"title":{"boost":1000.0},"text":{"boost":1.0},"tags":{"boost":1000000.0}}},"docs":[{"location":"","title":"JSON for Modern C++","text":""},{"location":"api/json/","title":"nlohmann::json","text":"<pre><code>using json = basic_json<>;\n</code></pre> <p>This type is the default specialization of the basic_json class which uses the standard template types.</p>"},{"location":"api/json/#examples","title":"Examples","text":"Example <p>The example below demonstrates how to use the type <code>nlohmann::json</code>.</p> <pre><code>#include <iostream>\n#include <iomanip>\n#include <nlohmann/json.hpp>\n\nusing json = nlohmann::json;\n\nint main()\n{\n // create a JSON object\n json j =\n {\n {\"pi\", 3.141},\n {\"happy\", true},\n {\"name\", \"Niels\"},\n {\"nothing\", nullptr},\n {\n \"answer\", {\n {\"everything\", 42}\n }\n },\n {\"list\", {1, 0, 2}},\n {\n \"object\", {\n {\"currency\", \"USD\"},\n {\"value\", 42.99}\n }\n }\n };\n\n // add new values\n j[\"new\"][\"key\"][\"value\"] = {\"another\", \"list\"};\n\n // count elements\n auto s = j.size();\n j[\"size\"] = s;\n\n // pretty print with indent of 4 spaces\n std::cout << std::setw(4) << j << '\\n';\n}\n</code></pre> <p>Output:</p> <pre><code>{\n \"answer\": {\n \"everything\": 42\n },\n \"happy\": true,\n \"list\": [\n 1,\n 0,\n 2\n ],\n \"name\": \"Niels\",\n \"new\": {\n \"key\": {\n \"value\": [\n \"another\",\n \"list\"\n ]\n }\n },\n \"nothing\": null,\n \"object\": {\n \"currency\": \"USD\",\n \"value\": 42.99\n },\n \"pi\": 3.141,\n \"size\": 8\n}\n</code></pre>"},{"location":"api/json/#version-history","title":"Version history","text":"<p>Since version 1.0.0.</p>"},{"location":"api/operator_gtgt/","title":"nlohmann::operator>>(basic_json)","text":"<pre><code>std::istream& operator>>(std::istream& i, basic_json& j);\n</code></pre> <p>Deserializes an input stream to a JSON value.</p>"},{"location":"api/operator_gtgt/#parameters","title":"Parameters","text":"<code>i</code> (in, out) input stream to read a serialized JSON value from <code>j</code> (in, out) JSON value to write the deserialized input to"},{"location":"api/operator_gtgt/#return-value","title":"Return value","text":"<p>the stream <code>i</code></p>"},{"location":"api/operator_gtgt/#exception-safety","title":"Exception safety","text":"<p>Strong guarantee: if an exception is thrown, there are no changes in <code>j</code>.</p>"},{"location":"api/operator_gtgt/#exceptions","title":"Exceptions","text":"<ul> <li>Throws <code>parse_error.101</code> in case of an unexpected token, or if <code>i</code> has no stream buffer (<code>i.rdbuf() == nullptr</code>, for instance <code>std::istream(nullptr)</code>).</li> <li>If reading from <code>i</code> reaches the end of the input and <code>eofbit</code> is part of <code>i</code>'s <code>exceptions()</code> mask, the <code>std::ios_base::failure</code> thrown by <code>i</code> itself propagates instead of a <code>parse_error</code>, the same as it would for the standard library's own extraction operators.</li> </ul>"},{"location":"api/operator_gtgt/#complexity","title":"Complexity","text":"<p>Linear in the length of the input. The parser is a predictive LL(1) parser.</p>"},{"location":"api/operator_gtgt/#notes","title":"Notes","text":"<p>A UTF-8 byte order mark is silently ignored.</p> <p>Invalid Unicode escapes and unpaired surrogates in the input are reported as <code>parse_error.101</code> with a detailed message.</p> <p><code>operator>></code> parses exactly one JSON value, so it can be called repeatedly to read a sequence of concatenated JSON values from the same stream:</p> <pre><code>json j1, j2;\ninput >> j1; // parses the first value\ninput >> j2; // parses the next value\n</code></pre> <p>A number must be followed by whitespace</p> <p>A number is only terminated by the character that follows it. That character is read from the stream to detect the end of the number, and it is not put back. When a value that is a number is immediately followed by the next value, the first character of that next value is lost:</p> <pre><code>std::istringstream input(\"1true\");\njson j1, j2;\ninput >> j1; // j1 == 1\ninput >> j2; // throws parse_error.101: the stream now starts at \"rue\"\n</code></pre> <p>Separating the values with whitespace avoids this, because the character that is eaten is then the separator:</p> <pre><code>std::istringstream input(\"1 true\");\njson j1, j2;\ninput >> j1; // j1 == 1\ninput >> j2; // j2 ==Line truncated
|
||||
Reference in new issue
Block a user