| 467 | } |
| 468 | |
| 469 | static JSON parse_object( const std::string &str, size_t &offset ) { |
| 470 | JSON Object( JSON::Class::Object ); |
| 471 | |
| 472 | ++offset; |
| 473 | consume_ws( str, offset ); |
| 474 | if( str.at(offset) == '}' ) { |
| 475 | ++offset; return Object; |
| 476 | } |
| 477 | |
| 478 | for (;offset<str.size();) { |
| 479 | JSON Key = parse_next( str, offset ); |
| 480 | consume_ws( str, offset ); |
| 481 | if( str.at(offset) != ':' ) { |
| 482 | throw std::runtime_error(std::string("JSON ERROR: Object: Expected colon, found '") + str.at(offset) + "'\n"); |
| 483 | } |
| 484 | consume_ws( str, ++offset ); |
| 485 | JSON Value = parse_next( str, offset ); |
| 486 | Object[Key.to_string()] = Value; |
| 487 | |
| 488 | consume_ws( str, offset ); |
| 489 | if( str.at(offset) == ',' ) { |
| 490 | ++offset; continue; |
| 491 | } |
| 492 | else if( str.at(offset) == '}' ) { |
| 493 | ++offset; break; |
| 494 | } |
| 495 | else { |
| 496 | throw std::runtime_error(std::string("JSON ERROR: Object: Expected comma, found '") + str.at(offset) + "'\n"); |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | return Object; |
| 501 | } |
| 502 | |
| 503 | static JSON parse_array( const std::string &str, size_t &offset ) { |
| 504 | JSON Array( JSON::Class::Array ); |