c# - NewtonSoft 反序列化嵌套的 JSON Blue Prism
问题描述
我正在使用 Blue Prism 调用 Microsoft 计算机视觉 API 来识别 PDF 中的文本。
获得 JSON 响应后,Blue Prism 使用 Blue Prism 的 JSON 实用程序或 Microsoft 计算机视觉技能上提供的操作将其转换为集合 (DataTable):获取读取操作响应。
问题:由于数据类型错误,Blue Prism 在某些情况下无法将 JSON 文本解析为集合。
有人可以建议将这种类型的 JSON 结构转换为 Blue Prism 可以读取的 DataTable 的代码吗?
我附上了 2 个 JSON 的 pastebin 链接(正文限制为 30000 个字符,不能在此处复制它们)。
在 Blue Prism 中可读(包含特殊字符 !"#$%&/()"'):
在 Blue Prism 中不可读:
Blue Prism 给出以下错误:
使用“获取读取操作响应”操作:
内部:意外错误数组中的数据类型不匹配:元素“3”具有类型而不是预期类型“System.Double”
使用“Blue Prism 的 JSON 实用程序”:
内部:无法执行代码阶段,因为代码阶段抛出异常:数组中的数据类型不匹配
我尝试通过使用 json2csharp.com 提供的工具创建公共类来将嵌套的 JSON 解析为数据表,然后指向它们并写入数据表。我还尝试不创建类,只需通过指向属性recognitionResults将 JSON 直接解析到数据表。
没有类:
数据集 ds = JObject.Parse(json_txt)["recognitionResults"].ToObject();
与类:
DataTable dt = (DataTable)JsonConvert.DeserializeObject(json_txt, (typeof(DataTable)));
课程:
public class Word
{
public List<double> boundingBox { get; set; }
public string text { get; set; }
public string confidence { get; set; }
}
public class Line
{
public List<double> boundingBox { get; set; }
public string text { get; set; }
public List<Word> words { get; set; }
}
public class RecognitionResult
{
public int page { get; set; }
public double clockwiseOrientation { get; set; }
public double width { get; set; }
public double height { get; set; }
public string unit { get; set; }
public List<Line> lines { get; set; }
}
public class RootObject
{
public string status { get; set; }
public List<RecognitionResult> recognitionResults { get; set; }
}
以下是 Blue Prism 中嵌套集合的外观: Blue Prism Nested Response Collection
解决方案
如果您使用的是版本 6 或更高版本,您应该看看 Blue Prism DX,这是社区的一个部门,用户可以在其中交换 VBO 和知识。这个问题已经解决了:
此实用程序提供将 JSON 解析为集合以及将集合转换为 JSON 的功能。
推荐阅读
- python - 为什么 Python 范围对于列表变量和字符串变量的行为似乎不同?
- qt - QML 布局:如何为行或列布局中的项目赋予权重?
- yocto - 在 Yocto 构建中禁用标准的 systemd 服务
- spring - 在 Spring DataJpaTest 中禁用生产数据源自动配置
- regex - 用 bat 查找字符串位置的最后一位数字的最佳选择
- python - 如何在 Python 中导入和捕获特定于模块的异常?
- sql - 你能交叉加入一个查询的结果吗
- python - Azure 事件中心 - ImportError:没有名为 eventhubs 的模块
- angular - 使上下文可用于传递给 ng-content 的模板
- python - 比较 2 个 csv 文件之间的列并使用 Python 编写差异