【发布时间】:2020-11-09 21:38:46
【问题描述】:
大家下午好,
我有一个我正在努力处理的问题
我正在使用第三方 Questions/Answers API,我问它一堆问题,它为他们提供可能的答案,这可能会导致更多问题
现在我只想将它们呈现在 HTML 中,但我的问题是,我正在将 JSON 从他们的 Web 服务反序列化为 C# 类,原始 JSON 看起来像
{
"questionDetails":[
{
"templateId":"T1000515",
"trees":[
{
"questions":[
{
"questionPhrase":"can this customer reported issue can be caused by accidental damage",
"answerType":"INT",
"questionId":"I100461"
},
{
"questionPhrase":"What damage is present on the display glass?",
"questionId":"Q100973",
"answers":[
{
"answerPhrase":"Single hairline crack with no point of impact",
"answerId":"A105795"
},
{
"answerPhrase":"Single hairline crack with a point of impact",
"answerId":"A105796"
},
]
},
{
"questionPhrase":"Was the customer using any third party accessories on the display?",
"questionId":"Q217845",
"answers":[
{
"answerPhrase":"Yes",
"questions":[
{
"questionPhrase":"Will the customer cover the cost of repair",
"questionId":"I217846",
"answers":[
{
"answerPhrase":"Yes",
"answerId":"A20062"
},
{
"answerPhrase":"No",
"answerId":"A20063"
}
]
}
],
"answerId":"A20062"
},
{
"answerPhrase":"No",
"answerId":"A20063"
}
]
}
],
"treeId":"TREE101678"
}
]
}
]
}
标准问题->答案很好,但在一些示例中,它的问题->答案->问题->答案->问题->答案,我猜它可以递归到 10-15 个问题设备。
我不太确定如何解决这个问题,我首先可能会尝试创建一个通用树然后渲染该树,但我不确定是否需要使用反射来检查类,或者真的如何要说如果答案引起更多问题,请继续添加,不要写大量的 if 语句
任何帮助将不胜感激。
谢谢
【问题讨论】:
-
我们似乎在同一天就开始解决这个问题。我一直在考虑将树渲染为一个平面 UL 列表,在分支上带有复选框和可能的文本或数字框,在描述路径的同一级别有一些隐藏类型输入,然后将其解析回 questionDetail。当然,它可能对一些 AJAX/jQuery 点击器更加用户友好,但它超出了我的能力范围......