c# - 出现错误无法将“Newtonsoft.Json.Linq.JObject”类型的对象转换为“Newtonsoft.Json.Linq.JArray”类型
问题描述
JObject joResponse = JObject.Parse(response);
JObject ojObject = (JObject)joResponse["d"];
JArray userResponseArray = (JArray)ojObject["results"];
foreach(JArray ja in userResponseArray)
{
----
}
对于 foreach 行,我遇到了错误
解决方案
JArray
JObject
在这种情况下包含一个数组,因此您JObject
在 JArray 中有集合,您的循环应如下所示:
foreach(JObject ja in userResponseArray)
{
string yourKey = item.GetValue("yourKey").ToString();
}
推荐阅读
- r - 将给定模式从字符串中的任何位置移动到正则表达式的起始位置
- javascript - 将模态对话框中的值返回到 html 表中的确切行
- ionic4 - ion-slides 方法在 ionic 4 中不起作用
- performance - 烘焙光增加我场景中的批次
- eclipse - eclipse新的gradle项目坚持任务初始化
- bash - 列出所有分支中比 master 上的最新标签年轻的所有标签
- amazon-web-services - Jenkins Cloudformation 插件给出 InValid Client Id 错误
- c# - 如何用 Task 输出字符串值
C#中的函数 - c++ - 用函数替换宏
- react-native - 有什么功能可以从 React Native 上传 Instagram 故事吗?