| 191 | } |
| 192 | |
| 193 | JSONValue JSONParser::ParseObject(){ |
| 194 | EatWhitespace(); |
| 195 | |
| 196 | if(!EatOne('{')){ |
| 197 | #ifdef LIBLEMON_DEBUG_JSON |
| 198 | printf("Expected {, line %d.\n", line); |
| 199 | #endif |
| 200 | return JSONValue(); |
| 201 | } |
| 202 | |
| 203 | std::map<JSONKey, JSONValue> values; |
| 204 | while(!End()){ |
| 205 | EatWhitespace(); |
| 206 | |
| 207 | std::string key = ParseString(); |
| 208 | if(!key.length()){ |
| 209 | #ifdef LIBLEMON_DEBUG_JSON |
| 210 | printf("Key is empty, line %d.\n", line); |
| 211 | #endif |
| 212 | return JSONValue(); |
| 213 | } |
| 214 | |
| 215 | EatWhitespace(); |
| 216 | |
| 217 | if(!EatOne(':')){ |
| 218 | #ifdef LIBLEMON_DEBUG_JSON |
| 219 | printf("Expected :, line %d.\n", line); |
| 220 | #endif |
| 221 | return JSONValue(); |
| 222 | } |
| 223 | |
| 224 | JSONValue v; |
| 225 | if(ParseValue(v)){ |
| 226 | return JSONValue(); // Error parsing value |
| 227 | } |
| 228 | |
| 229 | values[key] = v; |
| 230 | |
| 231 | EatWhitespace(); |
| 232 | |
| 233 | char c = Peek(); |
| 234 | if(c != ','){ // If there is a comma keep going, otherwise break |
| 235 | #ifdef LIBLEMON_DEBUG_JSON |
| 236 | printf("End of object '%c', line %d.\n", c, line); |
| 237 | #endif |
| 238 | break; |
| 239 | } else { |
| 240 | Eat(); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | EatWhitespace(); |
| 245 | if(!EatOne('}')){ |
| 246 | #ifdef LIBLEMON_DEBUG_JSON |
| 247 | printf("Expected }, line %d.\n", line); |
| 248 | #endif |
| 249 | return JSONValue(); |
| 250 | } |