Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.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
Javascript 为什么这个角色是&;恩达什&引用;成为“一个”吗&引用;在添加到JSON字符串并发布到REST web服务之后?_Javascript_Jquery_Json_Spring Mvc - Fatal编程技术网

Javascript 为什么这个角色是&;恩达什&引用;成为“一个”吗&引用;在添加到JSON字符串并发布到REST web服务之后?

Javascript 为什么这个角色是&;恩达什&引用;成为“一个”吗&引用;在添加到JSON字符串并发布到REST web服务之后?,javascript,jquery,json,spring-mvc,Javascript,Jquery,Json,Spring Mvc,我有一个带有编辑表单的网页,其中填充了数据库中的数据 我在一个角色上有问题,一个转义的n-破折号角色&ndash 输入字段如下所示 <input type="text" class="form-control" id="LocalName" name="LocalName" value="&ndash;" /> $("#doSaveEntityButton&

我有一个带有编辑表单的网页,其中填充了数据库中的数据

我在一个角色上有问题,一个转义的n-破折号角色<代码>&ndash

输入字段如下所示

<input type="text" class="form-control" id="LocalName"
   name="LocalName" value="&ndash;" /> 
$("#doSaveEntityButton").click(function() {

        var formData = {
            
            Name:$('#Name').val(),
            Region:$('#Region').val(),
            LocalName:$('#LocalName').val()

        }

        var sJSON = JSON.stringify(formData);
        alert("001: sJSON = "+sJSON);
001: sJSON = {"Name":"Antarctica","Region":"Antarctica","LocalName":"?"}
@RequestMapping(value = "/json/app/{appId}/{entityDefId}/saveentity", method = RequestMethod.POST)
public ResponseEntity<String> saveEntity(@PathVariable("appId") int appId, @PathVariable("entityDefId") int entityDefId, @RequestBody String json) throws Exception {
此时,警报中显示的文本如下所示

<input type="text" class="form-control" id="LocalName"
   name="LocalName" value="&ndash;" /> 
$("#doSaveEntityButton").click(function() {

        var formData = {
            
            Name:$('#Name').val(),
            Region:$('#Region').val(),
            LocalName:$('#LocalName').val()

        }

        var sJSON = JSON.stringify(formData);
        alert("001: sJSON = "+sJSON);
001: sJSON = {"Name":"Antarctica","Region":"Antarctica","LocalName":"?"}
@RequestMapping(value = "/json/app/{appId}/{entityDefId}/saveentity", method = RequestMethod.POST)
public ResponseEntity<String> saveEntity(@PathVariable("appId") int appId, @PathVariable("entityDefId") int entityDefId, @RequestBody String json) throws Exception {
请注意,LocalName值是一个“?”字符,而不是n-破折号甚至“-”

有趣的音符!我刚刚注意到,当我将此文本从“警报”对话框复制并粘贴到此处时,字符显示正确。。。就像这样

001: sJSON = {"Name":"Antarctica","Region":"Antarctica","LocalName":"–"}
    var sJSON = JSON.stringify(formData);
    alert("001: sJSON = "+sJSON);
    $.ajax({
            type : "POST",
            url : "/myapplication/json/saveentity", 
            data : sJSON,
            contentType: "application/json; charset=utf-8",
            dataType: "json",

        success : function(msg) {
            /* ... */
        },
        error : function(msg) {
            displayMessages(msg.responseJSON.messages);
        },
            done : function(e) {
        }
    });
});
这很有趣,但我仍然有我的问题

我的问题是。。。然后我将formData的sJSON字符串版本发布到我的web服务中,如下所示

001: sJSON = {"Name":"Antarctica","Region":"Antarctica","LocalName":"–"}
    var sJSON = JSON.stringify(formData);
    alert("001: sJSON = "+sJSON);
    $.ajax({
            type : "POST",
            url : "/myapplication/json/saveentity", 
            data : sJSON,
            contentType: "application/json; charset=utf-8",
            dataType: "json",

        success : function(msg) {
            /* ... */
        },
        error : function(msg) {
            displayMessages(msg.responseJSON.messages);
        },
            done : function(e) {
        }
    });
});
在web服务端,它显示为“?”字符。n-dash已丢失

我的Java Spring MVC web服务如下所示

<input type="text" class="form-control" id="LocalName"
   name="LocalName" value="&ndash;" /> 
$("#doSaveEntityButton").click(function() {

        var formData = {
            
            Name:$('#Name').val(),
            Region:$('#Region').val(),
            LocalName:$('#LocalName').val()

        }

        var sJSON = JSON.stringify(formData);
        alert("001: sJSON = "+sJSON);
001: sJSON = {"Name":"Antarctica","Region":"Antarctica","LocalName":"?"}
@RequestMapping(value = "/json/app/{appId}/{entityDefId}/saveentity", method = RequestMethod.POST)
public ResponseEntity<String> saveEntity(@PathVariable("appId") int appId, @PathVariable("entityDefId") int entityDefId, @RequestBody String json) throws Exception {
@RequestMapping(value=“/json/app/{appId}/{entityDefId}/saveentity”,method=RequestMethod.POST)
公共响应属性saveEntity(@PathVariable(“appId”)int-appId、@PathVariable(“entityDefId”)int-entityDefId、@RequestBody String json)引发异常{
所有其他类型的数据都可以正常工作


n-dash有什么不对吗?

那么为什么将
设置为
值呢?
“n-dash”字符是数据库中的值。它实际上来自MySQL“World”示例数据库。“Antartica”行来自“Country”表…这是该行的屏幕截图:值是否应该不是
?我通过使用Apache Commons库转义原始字符串来获得该值,如…
StringEscapeUtils.escapeHtml4(sValue);
…值字段中的字符不应该这样转义是问题吗?@charlietfl仅供参考,我只是尝试不使用StringEscapeUtils转义,这样它将显示为
value=“?”
…所以工作值不应该是常规文本(或空),而不是html实体