以下是我在这里要实现的目标:
我遇到的问题是尝试使用我收集的结果中的文件名。
运行代码时,会显示从数据库收集的原始JSON数据,但是当尝试仅列出文件名时,我什么也得不到(甚至不是错误)
有关如何解决这个问题的想法,并以一种让我以后搜索它们的方式列出文件名?或者有更好的方法吗?
另请注意:由于使用的SQL服务器版本,我必须使用FOR XML,因为FOR JSON不兼容。
编辑:使用Prany提供的代码我现在只能输出音频文件名,但我尝试输出sCallId我得到重复问题(见下面的输出):Getting Calls
2016\03\30\300320161614210106361-00000934412405.asf--84377-3668343241-514513
2016\03\30\300320161614210106361-00000934412405.asf--84385-3668343557-255773
2016\03\30\300320161614210106361-00000934412405.asf--84392-3668344445-516453
2016\03\30\300320161614210106361-00000934412405.asf--85000-3668749568-733799
2016\03\30\300320161614210106361-00000934412405.asf--85604-3668872399-722313
2016\03\30\300320161620220106362-00000934052048.asf--84377-3668343241-514513
2016\03\30\300320161620220106362-00000934052048.asf--84385-3668343557-255773
2016\03\30\300320161620220106362-00000934052048.asf--84392-3668344445-516453
2016\03\30\300320161620220106362-00000934052048.asf--85000-3668749568-733799
2016\03\30\300320161620220106362-00000934052048.asf--85604-3668872399-722313
2016\03\30\300320161634220106363-00000933211384.asf--84377-3668343241-514513
2016\03\30\300320161634220106363-00000933211384.asf--84385-3668343557-255773
2016\03\30\300320161634220106363-00000933211384.asf--84392-3668344445-516453
2016\03\30\300320161634220106363-00000933211384.asf--85000-3668749568-733799
2016\03\30\300320161634220106363-00000933211384.asf--85604-3668872399-722313
2016\04\04\040420160908190106389-00000527974488.asf--84377-3668343241-514513
2016\04\04\040420160908190106389-00000527974488.asf--84385-3668343557-255773
2016\04\04\040420160908190106389-00000527974488.asf--84392-3668344445-516453
2016\04\04\040420160908190106389-00000527974488.asf--85000-3668749568-733799
2016\04\04\040420160908190106389-00000527974488.asf--85604-3668872399-722313
2016\04\05\050420161913220106406-00000405271715.asf--84377-3668343241-514513
2016\04\05\050420161913220106406-00000405271715.asf--84385-3668343557-255773
2016\04\05\050420161913220106406-00000405271715.asf--84392-3668344445-516453
2016\04\05\050420161913220106406-00000405271715.asf--85000-3668749568-733799
2016\04\05\050420161913220106406-00000405271715.asf--85604-3668872399-722313
以下是我目前用来尝试执行此操作的代码。
//Run the SQL and wrap the output in results tags to fix Multiple Root Elements error.
string liveXML = "<results>" + cmd2.ExecuteScalar().ToString() + "</results>";
//Create new XML Document
XmlDocument LiveDoc = new XmlDocument();
LiveDoc.LoadXml(liveXML);
//Conver XML to JSON
sjsonLive = JsonConvert.SerializeXmlNode(LiveDoc);
//Output RAW JSON
txtOut.AppendText("\r\n" + sjsonLive);
//Parse JSON into an Array
var files = JObject.Parse(sjsonLive);
//We want to run this values in a files seach, but for now let's print it to txtOut
foreach (var f in files.SelectTokens("$..calls..@audioFileName"))
foreach (var c in files.SelectTokens("$..calls..@sCallID"))
{
txtOut.AppendText("\r\n" + f.ToString() + " - " + c.ToString());
//Conduct File Search Here...
}
示例JSON数据:
{
"results": {
"calls": [{
"@audioFileName": "2016\\03\\30\\300320161614210106361-00000934412405.asf",
"@sCallID": "84377-3668343241-514513"
}, {
"@audioFileName": "2016\\03\\30\\300320161620220106362-00000934052048.asf",
"@sCallID": "84385-3668343557-255773"
}, {
"@audioFileName": "2016\\03\\30\\300320161634220106363-00000933211384.asf",
"@sCallID": "84392-3668344445-516453"
}, {
"@audioFileName": "2016\\04\\04\\040420160908190106389-00000527974488.asf",
"@sCallID": "85000-3668749568-733799"
}, {
"@audioFileName": "2016\\04\\05\\050420161913220106406-00000405271715.asf",
"@sCallID": "85604-3668872399-722313"
}
]
}
}
答案 0 :(得分:1)
编辑:
您可以使用以下标记选择器
var calls = files.SelectTokens("$..calls..@sCallID").ToList();
var audiofiles = files.SelectTokens("$..calls..@audioFileName").ToList();
for (int i = 0; i <= audiofiles.Count; i++)
{
//Conduct File search
if (true)
{
//access by index like audiofiles[i] and append to the query
}
else
{
//access calls by index like calls[i] and append to the query
}
}
编辑2:
boundingRect