Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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
Botframework Can';t在旋转木马英雄卡中显示项目_Botframework_Azure Bot Service - Fatal编程技术网

Botframework Can';t在旋转木马英雄卡中显示项目

Botframework Can';t在旋转木马英雄卡中显示项目,botframework,azure-bot-service,Botframework,Azure Bot Service,目前我想将JSON转换为Carousel HeroCard 当我调试时 显示的错误 System.ArgumentException:无法将数组转换为字符串。 在Newtonsoft.Json.Linq.JToken.op_显式(JToken值) 这是我的JSON { "@odata.context": "https://Cognitivesearch.search.windows.net/indexes('testindex1')/$metadata#docs(*)", "va

目前我想将JSON转换为Carousel HeroCard

当我调试时

显示的错误

System.ArgumentException:无法将数组转换为字符串。 在Newtonsoft.Json.Linq.JToken.op_显式(JToken值)

这是我的JSON

{
    "@odata.context": "https://Cognitivesearch.search.windows.net/indexes('testindex1')/$metadata#docs(*)",
    "value": [     
        {
            "@search.score": 0.03393994,
            "metadata_storage_name": "DRSK.xlsm",
            "metadata_storage_path": "aHR0cHM6Ly9rcG1nc2VhcmNoc3RvcmFnZS5ibG9iLmNvcmUud2luZG93cy5uZXQvYmFzaWNkZW1vL0RSU0sueGxzbQ2",
            "text": [
                "Excel Template Excel Template Unique tickers: 2 Display Rows: Valid(8) .Invalid(0) o All(8) Company Name Ticker Country Sector Currency Announced Date (mm/dd/yy) 1. V R&R ICE CREAM RRR1 US Food & Bevera |GBP 2/14/12 @ 2. J R&R ICE CREAM RRR1 US Food & Bevera GBP 2/14/11 0 3. V RAR ICE CREAM RRR1 US Food & Bevera GBF 2/14/10 @ 4. R&R ICE CREAM RRR1 US Food & Bevera GBP 2/14/09 @ 5. V R&R ICE CREAM RRR1 US Food & Bevera GBP 2/14/08 @ 6. / R&R ICE CREAM RRR1 US Food & Bevera |GBP 2/14/07 0 3. V DUKE FIRST BA DUKETST US Banks USD 1/31/14 @ B. / DUKE FIRST BA DUKETST US Banks USD 10/22/13 @ 2 Export to Excel D Upload Cancel",
                "Excel Template Excel Template Step 1: 10) Download Template Step 2: Fill Data in Template Option 1 - Enter data manually or Option 2 - Cut and paste from your Excel workshee Do not change format or order of the columns. Step 3: Highlight data, drag, and drop here To highlight your data in Excel, select headers and data in Excel. Next, move your mouse pointer to the border of the selected area till the mouse pointer changes to a plus (+) with arrows. Left-click and drag the selection into this popup. Close"
            ]
        },

        {
            "@search.score": 0.0032757183,
            "metadata_storage_name": "DRSK non financial private companies white paper.pdf",
            "metadata_storage_path": "aHR0cHM6Ly9rcG1nc2VhcmNoc3RvcmFnZS5ibG9iLmNvcmUud2luZG93cy5uZXQvYmFzaWNkZW1vL0RSU0slMjBub24lMjBmaW5hbmNpYWwlMjBwcml2YXRlJTIwY29tcGFuaWVzJTIwd2hpdGUlMjBwYXBlci5wZGY1",
            "text": [
                "Bloomberg",
                "Technical Default Grace Period Default Resolution Bankruptcy Failure to Pay Coupon Positive Resolution: Firm Attempts to Firm Survives Violation of Fix Situation Debt Covenants Negative Resolution: Default Bankruptcy Figure 1 - Time line for default",    
                "1-Yr Default Prob 17.2533 35 32.2807 30 25 20 15 10 Jun Sep Dec Mar Jun Sep Dec Mar Jun Sep 2007 2008 2009 Copyright 2016 Bloomberg Finance L.P. 12-Jan-2016 14:08:33",

            ]
        }
    ]
}
这里是我的源代码

   try
        {
            var content = response.Content;
            JObject jObj = JObject.Parse(jsoncontent);
            JArray jarr = (JArray)jObj["value"];

            var attachments = new List<Attachment>();
            foreach (JToken item in jarr)
            {
                var filename = (string)item.SelectToken("metadata_storage_name");
                var filepath = (string)item.SelectToken("metadata_storage_path");
                var desc = (string)item.SelectToken("text");

                var heroCard = new HeroCard(
                    title: filename,
                    subtitle: desc
                    ).ToAttachment();
                attachments.Add(heroCard);

            }

            var reply = MessageFactory.Carousel(attachments);
            await turnContext.SendActivityAsync(reply);
        }catch(Exception ex)
        {
            await turnContext.SendActivityAsync(ex.ToString());
        }
试试看
{
var content=response.content;
JObject-jObj=JObject.Parse(jsoncontent);
JArray jarr=(JArray)jObj[“值”];
var attachments=新列表();
foreach(jarr中的JToken项目)
{
var filename=(字符串)item.SelectToken(“元数据存储名称”);
var filepath=(字符串)item.SelectToken(“元数据存储路径”);
var desc=(字符串)item.SelectToken(“文本”);
var heroCard=新heroCard(
标题:文件名,
字幕:描述
).ToAttachment();
附件.添加(heroCard);
}
var reply=MessageFactory.Carousel(附件);
等待turnContext.SendActivityAsync(回复);
}捕获(例外情况除外)
{
等待turnContext.SendActivityAsync(例如ToString());
}

我想在HeroCard中显示“元数据存储名称”和“文本”


高级感谢。

您遇到的问题是“文本”部分-在JSON中,它不是单个值,而是字符串值数组。因此,你需要思考你到底想如何处理这个问题

以下是给出问题的特定行:

var desc=(字符串)项。选择标记(“文本”)

要实际检索这些字符串值,可以将其作为字符串数组导入,如下所示:

string[]descriptions=item.SelectToken(“文本”).ToObject()

(我不是在测试上面一行中的空值,对于“text”,您可能应该这样做)

一旦拥有了该数组,就需要决定如何处理它。例如,您可能希望将它们全部连接起来,并用“;”将它们分开,例如“测试1”和“测试2”将显示为“测试1;测试2”作为最终描述。像这样的东西看起来像:

string[] descriptions = item.SelectToken("text").ToObject<string[]>();
var desc = string.Join("; ", descriptions); 
string[]descriptions=item.SelectToken(“文本”).ToObject();
var desc=string.Join(“;”,说明);
这将为您提供一个与“desc”变量关联的“description”,此时您可以使用它执行任何操作


如果选择文本中的第一项,希望这会有所帮助,这将是“var desc=descriptions[0];”,但您应该首先检查数组中是否有任何项在第一项中(例如,“if(descriptions.Count>0)