为什么我到处都是“\”?
我使用的方法:
@RequestMapping(value = '/showFromMongo', method = RequestMethod.GET)
def showFromMongoDB() {
//println 'testit'
def obj = repository.findByLastName("Vinodh");
ObjectMapper myObjectMapper = new ObjectMapper();
myObjectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
def temp = []
obj.collect{
temp << myObjectMapper.writeValueAsString(it)
}
temp
}
输出我得到:
[
"{\"id\":\"54fe7bbfd416859826ae53ea\",\"firstName\":\"Priya\",\"lastName\":\"Vinodh\"}",
"{\"id\":\"54fe7be8d416f74f961678fa\",\"firstName\":\"Mrithula\",\"lastName\":\"Vinodh\"}"
]
应该怎么做才能消除“\”。