Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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
Groovy HttpBuilder json输入故障_Json_Groovy_Httpbuilder - Fatal编程技术网

Groovy HttpBuilder json输入故障

Groovy HttpBuilder json输入故障,json,groovy,httpbuilder,Json,Groovy,Httpbuilder,我在将json参数传递到web操作时遇到问题。我知道web操作在指定的urlhttp://projects.example.net/example/bugnetwebservice.asmx/MobileBuildAction,正如我用带有json参数的postman测试过的: { featureIdStr: 31, actionStr: 1, comment: "Hello world" } 并得到回应: { "d": "Succeeded" } 但是,每当

我在将json参数传递到web操作时遇到问题。我知道web操作在指定的url
http://projects.example.net/example/bugnetwebservice.asmx/MobileBuildAction
,正如我用带有json参数的postman测试过的:

{
    featureIdStr: 31,
    actionStr: 1,
    comment: "Hello world"
}
并得到回应:

{
    "d": "Succeeded"
}
但是,每当我尝试在groovy中运行它时,都会得到以下响应:

Jun 10, 2016 9:54:25 AM net.sf.json.JSONObject _fromBean
INFO: Property 'value' of class org.codehaus.groovy.runtime.GStringImpl has no read method. SKIPPED
Failure: 500
这是我的密码:

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*

def http = new HTTPBuilder("http://projects.example.net/")
def issueId = 31
def msg = "Build Failed"
def jsonBody = [:]
jsonBody.put("featureIdStr", issueId)
jsonBody.put("actionStr", 0)
jsonBody.put("comment", "${msg}: <a href='http://www.google.com'}'>Googles Job</a>")
http.request(POST, JSON) {
    uri.path = "/example/bugnetwebservice.asmx/MobileBuildAction"
    body = jsonBody

    response.success = { resp ->
        println "Success! ${resp.status}"
    }

    response.failure = { resp ->
        println "Failure: ${resp.status}"
    }
}
@Grab(group='org.codehaus.groovy.modules.httpbuilder',module='http-builder',version='0.7.1')
导入groovyx.net.http*
导入静态groovyx.net.http.ContentType*
导入静态groovyx.net.http.Method*
def http=新的HTTPBuilder(“http://projects.example.net/")
def issueId=31
def msg=“构建失败”
def jsonBody=[:]
jsonBody.put(“featureIdStr”,issueId)
jsonBody.put(“actionStr”,0)
jsonBody.put(“comment”、“${msg}:”)
请求(POST,JSON){
uri.path=“/example/bugnetwebservice.asmx/MobileBuildAction”
body=jsonBody
response.success={resp->
println“成功!${resp.status}”
}
response.failure={resp->
println“失败:${resp.status}”
}
}
请帮忙

jsonBody.put(“comment”,“${msg}:http://www.google.com“谷歌工作”)

Groovy中的“”创建一个Groovy字符串(也称为GString)。gstring很好-它们允许
${}
语法-但是它们在序列化和反序列化自身时存在一些问题。有一个很棒的

总之,它的缺点是,在那篇文章和我自己的经历之间:任何时候你在比较或者序列化Groovy字符串,首先调用
toString()

我会考虑编写你的代码:

def commentValue = "${msg}: <a href='http://www.google.com'}'>Googles Job</a>"

jsonBody.put( commentValue.toString() )
def commentValue=“${msg}:”
jsonBody.put(commentValue.toString())

能否尝试将最后一个
put
值更改为
“${msg}:”.toString()
?我想我遇到过与HTTPBuilder中字符串与GString处理相关的类似问题。