在grails中的度符号

时间:2016-05-11 03:41:05

标签: json grails utf-8 http-get

您好我正在接受请求获取包含度数符号的JSON。

 def get(url){
        url = new URL(url)
        def connection = url.openConnection()
        connection.setRequestMethod("GET")
        connection.setRequestProperty("Accept", "application/json;charset=utf-8");


        connection.doOutput = true
        connection.connect()

        print resp
        resp

    }

但我的符号在浏览器上查看时显示单位“:” C“,在控制台中显示�。如何解决?

1 个答案:

答案 0 :(得分:0)

尝试使用JsonSlulrper从URL处理json数据,如下所示:

def resp = new JsonSlurper().parseText(url.text)

同样在HTML视图/布局中,请确保应用编码:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    ........