Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
缺少拼写字符的Java REST响应值_Java_Json_Rest_Spelling - Fatal编程技术网

缺少拼写字符的Java REST响应值

缺少拼写字符的Java REST响应值,java,json,rest,spelling,Java,Json,Rest,Spelling,我用Java编写了REST,JSON响应消息无效 我在单文件messages.properties中定义了消息。我希望回应应该是这样的: NOT_FOUND_PERSON = Person doesn't exist 但是,我得到的答复是缺少拼写: ['errorMsg': 'Person doesnt exist.'] 问题在哪里?不能是因为配置中的安装资源BundleMessageSource错误?我注意到缺少UTF8编码。 某些隐藏转义函数或其他函数有问题吗?我在JSON字符串中使用了

我用Java编写了REST,JSON响应消息无效


我在单文件messages.properties中定义了消息。我希望回应应该是这样的:

NOT_FOUND_PERSON = Person doesn't exist
但是,我得到的答复是缺少拼写:

['errorMsg': 'Person doesnt exist.']
问题在哪里?不能是因为配置中的安装资源BundleMessageSource错误?我注意到缺少UTF8编码。
某些隐藏转义函数或其他函数有问题吗?

我在JSON字符串中使用了双引号

{
    "objectDetail": {
        "id": "1",
        "anotherId": "1",
        "errorText": "This element doesn't exist."
    }
}
我试着用你的数据

['errorMsg': 'Person doesn't exist.']
这是我的示例,它返回一个转换为JSON字符串的对象

@RestController
@RequestMapping(method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public class JsonRestController {

    @RequestMapping("/api/{id}")
    public ResponseEntity<RestObject> getModel(@PathVariable Long id) {
         RestObject restObject = restService.getModel(id);
         return new ResponseEntity<>(restObject, HttpStatus.OK);
    }
}


我找到了解决办法。问题在于messages.properties中的引号。 默认情况下,spring使用消息包表示属性文件中的消息。任何引号的出现都必须通过单引号转义,否则将无法正确显示

这个

必须用这个来代替

test.message2={0}''s message
资源:

请显示您的服务器端是如何编码的。我对Rest控制器或RestResource感兴趣,不管您对Rest服务器使用什么框架。我在单文件messages.properties中定义了消息。不能是因为配置中的安装资源BundleMessageSource错误?我注意到缺少UTF8编码。我不知道。
test.message2={0}'s message
test.message2={0}''s message