7

Scenario :

I am using following code to decode a JSON String to generate the objects using it.

enter image description here

{"av":{"tid":"1000","sslist":[{"ss":{"ssId":"1","ssName":"Test ss "name one"}},{"ss":{"ssId":"2","ssName":"Test ss name two"}}],"hl":{"lc":0}}}

Now, I have hundreds elements of sslist and all are failed because of one bloody " in ssName in the first ss element.

But this error is throwing when the String is parsing at the very beginning at the createJsonParser() method.

Question :

I want to ignore the error prone node only and proceed with other hundred of correct nodes. Is there any other method to do this?

Code :

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;

public class JsonReader {

        private void readJsonMethodThree(String jsonString) throws JsonParseException, IOException{

            ObjectMapper    mapper          = new ObjectMapper();
            JsonFactory     factory         = mapper.getJsonFactory();
            JsonParser      jsonParser      = factory.createJsonParser(jsonString);
            JsonNode        jsonNode        = mapper.readTree(jsonParser);

        }

}

Exception :

Exception in thread "main" com.fasterxml.jackson.core.JsonParseException: Unexpected character ('n' (code 110)): was expecting comma to separate OBJECT entries
 at [Source: java.io.StringReader@12cc95d; line: 1, column: 69]
4

2 回答 2

4
yourjsonstring = yourjsonstring.replaceAll("\"name", "name");

或使用更通用的模式,这只是示例。

于 2013-07-12T16:17:22.367 回答
0

当 JSON 的数据类型与 cassandra 中声明的类型不匹配时,您也可能会收到此错误。具体来说,检查 JSON 值是否实际上应该是一个list类型而不是单例。

于 2017-05-08T13:07:22.480 回答