替换一个词以访问 Jolie 中的 json 数据
Substitute a word to access json data in Jolie
我有一个 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 是动态的,基于用户的输入,我需要形成密钥,然后对其求值和 return 响应。
我希望这条线是
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)
我有一个 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 是动态的,基于用户的输入,我需要形成密钥,然后对其求值和 return 响应。
我希望这条线是
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)