Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 875c8fd

Browse files
authored
Merge pull request simdjson#1071 from pps83/quick-example-at-the-top-of-simdjson.h
Add a quick example at the top of simdjson.h
2 parents a0b1642 + 164fcb4 commit 875c8fd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎include/simdjson.h‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,33 @@
55
* @mainpage
66
*
77
* Check the [README.md](https://github.com/lemire/simdjson/blob/master/README.md#simdjson--parsing-gigabytes-of-json-per-second).
8+
*
9+
* Sample code. See https://github.com/simdjson/simdjson/blob/master/doc/basics.md for more examples.
10+
11+
#include "simdjson.h"
12+
13+
int main(void) {
14+
// load from `twitter.json` file:
15+
simdjson::dom::parser parser;
16+
simdjson::dom::element tweets = parser.load("twitter.json");
17+
std::cout << tweets["search_metadata"]["count"] << " results." << std::endl;
18+
19+
// Parse and iterate through an array of objects
20+
auto abstract_json = R"( [
21+
{ "12345" : {"a":12.34, "b":56.78, "c": 9998877} },
22+
{ "12545" : {"a":11.44, "b":12.78, "c": 11111111} }
23+
] )"_padded;
24+
25+
for (simdjson::dom::object obj : parser.parse(abstract_json)) {
26+
for(const auto& key_value : obj) {
27+
cout << "key: " << key_value.key << " : ";
28+
simdjson::dom::object innerobj = key_value.value;
29+
cout << "a: " << double(innerobj["a"]) << ", ";
30+
cout << "b: " << double(innerobj["b"]) << ", ";
31+
cout << "c: " << int64_t(innerobj["c"]) << endl;
32+
}
33+
}
34+
}
835
*/
936

1037
#include "simdjson/compiler_check.h"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /