From: Frédéric S. <fre...@ar...> - 2009-11-18 14:43:39
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body bgcolor="#ffffff" text="#000000"> Hi,<br> <br> Example :<br> <br> {<br> "test":<br> [<br> { "a" : "aaa" }, // Comment for a<br> { "b" : "bbb" }, // Comment for b<br> { "c" : "ccc" } // Comment for c<br> ]<br> }<br> <br> With this example you get an error : "Missing ',' or ']' in array declaration" for "// Comment for c"<br> <br> I fixed the problem by reading tokens in the same way readObject() does.<br> <br> Fixed version of readArray() :<br> <br> <tt>bool<br> Reader::readArray( Token &tokenStart )<br> {<br> currentValue() = Value( arrayValue );<br> skipSpaces();<br> if ( *current_ == ']' ) // empty array<br> {<br> Token endArray;<br> readToken( endArray );<br> return true;<br> }<br> int index = 0;<br> while ( true )<br> {<br> Value &value = currentValue()[ index++ ];<br> nodes_.push( &value );<br> bool ok = readValue();<br> nodes_.pop();<br> if ( !ok ) // error already set<br> return recoverFromError( tokenArrayEnd );<br> <br> Token token;<br> <font color="#3333ff"><b> // Accept Comment after last item in the array.<br> ok = readToken( token );<br> while ( token.type_ == tokenComment && ok )<br> ok = readToken( token );<br> if( ! ok<br> </b></font> || ( token.type_ != tokenArraySeparator &&<br> token.type_ != tokenArrayEnd ) )<br> {<br> return addErrorAndRecover( "Missing ',' or ']' in array declaration",<br> token,<br> tokenArrayEnd );<br> }<br> if ( token.type_ == tokenArrayEnd )<br> break;<br> }<br> return true;<br> }<br> </tt><br> <br> Regards,<br> Frédéric SURLEAU.<br> <br> </body> </html> |