| 187 | } |
| 188 | |
| 189 | Value parseObject() { |
| 190 | if (depth >= MAX_DEPTH) return Value(); |
| 191 | ++depth; |
| 192 | next(); // skip { |
| 193 | Value v; |
| 194 | v.type = Type::Object; |
| 195 | skipWs(); |
| 196 | if (peek() == '}') { next(); --depth; return v; } |
| 197 | while (true) { |
| 198 | skipWs(); |
| 199 | if (peek() != '"') break; // key must start with quote |
| 200 | auto key = parseString(); |
| 201 | skipWs(); |
| 202 | next(); // skip : |
| 203 | auto val = parseValue(); |
| 204 | v.objVal[key.strVal] = std::move(val); |
| 205 | skipWs(); |
| 206 | if (peek() == ',') { next(); continue; } |
| 207 | if (peek() == '}') { next(); break; } |
| 208 | break; |
| 209 | } |
| 210 | --depth; |
| 211 | return v; |
| 212 | } |
| 213 | }; |
| 214 | |
| 215 | Value Parse(const std::string& json) { |