替换一个单词来访问Jolie中的json数据



我有一个创建为的Glossary.json文件

{
"glossary": {
"program": "A set of instructions",
"OS": "Operating System"
}
}

然后我有一个写为的jolie文件

include "file.iol"
type GlossaryRequest { queryWord : string }
type Glossary { glossary : string }
interface GlossaryInterface {
RequestResponse : fetchDefinition (GlossaryRequest) (Glossary)
}
service GlossaryService {
inputPort GlossaryInput {
location: "socket://localhost:8081"
protocol: http { format = "json" }
interfaces: GlossaryInterface
}

main {
readFile@File( {
filename = "glossary.json"
format = "json"
} )( data )
fetchDefinition (request) (response) {
key = "data.glossary." + request.queryWord
response.glossary = key //This is the line concerned
}
}
}

由于queryWord是动态的,基于用户的输入,我需要形成密钥,然后对其进行评估并返回响应。

我希望这条线路是

response.glossary = data.glossary.OS or data.glossary.program, based on the input to URL
The URL would be "http://localhost:8081/fetchDefinition?queryWord=program

有任何实现这一目标的提示或方向吗?否则,如何在数据中搜索输入字符串?

如果我在Jolie文档页面上搜索了更多的例子,我就不需要发布这个问题了。无论如何,我在";动态绑定";。

答案是这样使用:

response.glossary = data.glossary.(request.queryWord)

最新更新