belikeswap / quick-json

Automatically exported from code.google.com/p/quick-json
0 stars 0 forks source link

Exception when parsing empty string #7

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create the java Class
package experiment;
import java.util.Map;
import com.json.parsers.JSONParser;
import com.json.parsers.JsonParserFactory;

public class Dummy {
    public static void main(String[] args) {

        JsonParserFactory factory=JsonParserFactory.getInstance();
        JSONParser parser = factory.newJsonParser();
        String strJSONtoParse = "{\"id\":\"[EMPTY]\",\"AN_Response\":\"\"}";
        System.out.println("Parsing of : " + strJSONtoParse);
        Map mapModel = parser.parseJson(strJSONtoParse);
        System.out.println("Empty String : '" + mapModel.get("AN_Response")+"'");
    }
}

2.  Run the Class (execute "main()")

What is the expected output? What do you see instead?
>>expected output console:
Parsing of : {"id":"[EMPTY]","AN_Response":""}
Empty String : ''
>> what I see
Parsing of : {"id":"[EMPTY]","AN_Response":""}
Exception in thread "main" com.json.exceptions.JSONParsingException: 
@Key-Heirarchy::root/   @Key::AN_Response   Value is expected but found 
empty...@Position::32
    at com.json.utils.JSONUtility.handleFailure(JSONUtility.java:124)
    at com.json.parsers.JSONParser.stringLiteralTemplate(JSONParser.java:580)
    at com.json.parsers.JSONParser.nonValidatingValueTemplate(JSONParser.java:698)
    at com.json.parsers.JSONParser.parseValue(JSONParser.java:377)
    at com.json.parsers.JSONParser.parseKeysValues(JSONParser.java:254)
    at com.json.parsers.JSONParser.parseJsonBody(JSONParser.java:232)
    at com.json.parsers.JSONParser.parseJsonBlock(JSONParser.java:212)
    at com.json.parsers.JSONParser.parseJson(JSONParser.java:139)
    at experiment.Dummy.main(Dummy.java:20)

What version of the product are you using? On what operating system?
OS : OpsenSUSE linux 12.3 x86_64
jdk : 1.7.0_40
Eclipse : Luna build id: 20131113-1838
quickjson : 1.0.2.3

Please provide any additional information below.
/

Original issue reported on code.google.com by each.dev...@gmail.com on 17 Dec 2013 at 8:48

GoogleCodeExporter commented 9 years ago
I ran into a very similar error:
  JsonParserFactory factory = JsonParserFactory.getInstance();
  JSONParser parser = factory.newJsonParser();
  content = "{\"foo\":[\"apple\", \"\", \"banana\"]}";
  Map jsonData = parser.parseJson(content);

So the content is {"foo":["apple", "", "banana"]}, and parsing it causes an 
error at the empty string between apple and banana.

The error message I get is:
com.json.exceptions.JSONParsingException: @Key-Heirarchy::root/foo[1]/ @Key:: 
Value is expected but found empty...@Position::19

I am using JDK 1.6 32-bit on Windows 7 64-bit.

(Also, @Key-Heirarchy should probably be spelled @Key-Hierarchy)

Original comment by bobth...@gmail.com on 4 Mar 2014 at 4:07

GoogleCodeExporter commented 9 years ago
Should be fixed in https://code.google.com/p/quick-json/issues/detail?id=11

Original comment by noack.mi...@googlemail.com on 23 Oct 2014 at 3:36