| 1580 | } |
| 1581 | |
| 1582 | Dictionary *DictionaryFromString(const FString &string) |
| 1583 | { |
| 1584 | if (string.Compare("null") == 0) |
| 1585 | { |
| 1586 | return nullptr; |
| 1587 | } |
| 1588 | |
| 1589 | Dictionary *const dict = Create<Dictionary>(); |
| 1590 | |
| 1591 | if (string.IsEmpty()) |
| 1592 | { |
| 1593 | return dict; |
| 1594 | } |
| 1595 | |
| 1596 | rapidjson::Document doc; |
| 1597 | doc.Parse(string.GetChars(), string.Len()); |
| 1598 | |
| 1599 | if (doc.GetType() != rapidjson::Type::kObjectType) |
| 1600 | { |
| 1601 | I_Error("Dictionary is expected to be a JSON object."); |
| 1602 | return dict; |
| 1603 | } |
| 1604 | |
| 1605 | for (auto i = doc.MemberBegin(); i != doc.MemberEnd(); ++i) |
| 1606 | { |
| 1607 | if (i->value.GetType() != rapidjson::Type::kStringType) |
| 1608 | { |
| 1609 | I_Error("Dictionary value is expected to be a JSON string."); |
| 1610 | return dict; |
| 1611 | } |
| 1612 | |
| 1613 | dict->Map.Insert(i->name.GetString(), i->value.GetString()); |
| 1614 | } |
| 1615 | |
| 1616 | return dict; |
| 1617 | } |
| 1618 | |
| 1619 | template<> FSerializer &Serialize(FSerializer &arc, const char *key, Dictionary *&dict, Dictionary **) |
| 1620 | { |