2016-12-09 7 views
1

Rest Spring: 出力に何が起こったのか理解するには?Springのjsonのスラッシュ

@RestController 
@RequestMapping("/person") 
public class PersonController { 

    @Autowired 
    PersonService personService; 

    @RequestMapping(value = "/persons", method = RequestMethod.GET) 
    public String findAll() { 

     try { 
      List<Person> listModel = null; 

      listModel = personService.findAll(); 
      Gson gson = new Gson(); 

      System.out.println(gson.toJson(listModel)); 

      return gson.toJson(listModel); 
     } catch (Exception e) { 
      return e.getMessage(); 
     } 

    } 
} 

出す:

[{"ID":1,"firstName":"j","lastName":"s","nationalCode":1-86,"gender":"male","fatherName":"sss","deleted":"0"}] 

が、ブラウザで(スラッシュ)である:

"[{\"ID\":1,\"firstName\":\"j\",\"lastName\":\"s\",\"nationalCode\":1-86,\"gender\":\"male\",\"fatherName\":\"sss\",\"deleted\":\"0\"}]" 

、それは

答えて

1

何も問題ありません。これはあなたのjson文字列の二重引用符をエスケープしています。それを見るもう1つの方法は、文字列内に二重引用符があり、これを伝える方法です。

0

\を解決することができる方法は何ですかので、エスケープ文字であります文字列に"を含めることができます

関連する問題