我有一个JSON字符串:
"[{\"is_translator\":false,\"follow_request_sent\":false,\"statuses_count\":1058}]"在字符串上使用PHP的json_decode()并执行print_r,输出:
Array
(
[0] => stdClass Object
(
[is_translator] =>
[follow_request_sent] =>
[statuses_count] => 1058
)
)这表明它是有效的JSON。
但是使用Jackson Library会产生一个错误:
Exception in thread "main"
org.codehaus.jackson.map.JsonMappingException: Can not deserialize
instance of java.util.LinkedHashMap out of START_ARRAY token at
[Source: java.io.StringReader@a761fe; line: 1, column: 1]
这是简单的代码:
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
public class tests {
public static void main(String [] args) throws IOException{
ObjectMapper mapper = new ObjectMapper();
Map fwers = mapper.readValue("[{\"is_translator\":false,\"follow_request_sent\":false,\"statuses_count\":1058}]", new TypeReference >() {});
System.out.println(fwers.get("statuses_count"));
}
}有人能告诉我什么是错误的和解决方案?
谢谢。