Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
mir.ion.deser.json
- T
deserializeJson
(T)(scope const(char)[]text
); - Examples:Test @nogc deserialization
import mir.serde: serdeIgnoreIn, serdeIgnore, serdeScoped; import mir.bignum.decimal; import mir.rc.array; import mir.small_array; import mir.small_string; static struct Book { SmallString!64 title; bool wouldRecommend; SmallString!128 description; // common `string` and array can be used as well (with GC) uint numberOfNovellas; Decimal!1 price; double weight; // nogc small-array tags SmallArray!(SmallString!16, 10) smallArrayTags; // nogc rc-array tags RCArray!(SmallString!16) rcArrayTags; // nogc scope array tags // when used with `@property` and `@serdeScoped` @serdeIgnore bool tagsSet; // control flag for test @serdeScoped void tags(scope SmallString!16[] tags) @property @safe pure nothrow @nogc { assert(tags.length == 3); assert(tags[0] == "one"); assert(tags[1] == "two"); assert(tags[2] == "three"); tagsSet = true; } } auto book = q{{ "title": "A Hero of Our Time", "wouldRecommend": true, "description": null, "numberOfNovellas": 5, "price": 7.99, "weight": 6.88, "tags": [ "one", "two", "three" ], "rcArrayTags": [ "russian", "novel", "19th century" ], "smallArrayTags": [ "4", "5", "6" ] }} .deserializeJson!Book; import mir.conv: to; assert(book.description.length == 0); assert(book.numberOfNovellas == 5); assert(book.price.to!double == 7.99); assert(book.tagsSet); assert(book.rcArrayTags.length == 3); assert(book.rcArrayTags[0] == "russian"); assert(book.rcArrayTags[1] == "novel"); assert(book.rcArrayTags[2] == "19th century"); assert(book.smallArrayTags.length == 3); assert(book.smallArrayTags[0] == "4"); assert(book.smallArrayTags[1] == "5"); assert(book.smallArrayTags[2] == "6"); assert(book.title == "A Hero of Our Time"); assert(book.weight == 6.88); assert(book.wouldRecommend);
- SerdeException
deserializeValueFromJson
(T)(scope const(char)[]text
, ref Tvalue
);
Copyright © 2016-2021 by Ilya Yaroshenko | Page generated by
Ddoc on Fri Jan 22 07:49:00 2021