【发布时间】:2021-09-04 06:20:21
【问题描述】:
我假设我在这里犯了一个愚蠢的错误,但想知道是否有人可以提供帮助?
我正在尝试以下库:
Install-Package RulesEngine -Version 3.2.0
我的rules.json如下:
[
{
"WorkflowName": "DeliverToMatchingSuburb",
"Rules": [
{
"RuleName": "MatchingSuburb",
"Expression": "customer.PostCode == location.PostCode"
}
]
}
]
我的代码:
string[] readText = File.ReadAllLines("rules.json");
Customer c = new Customer();
Pharmacy p = new Pharmacy();
var pharmacies = p.GetLocations();
var customers = c.GenerateCustomers();
var re = new RulesEngine.RulesEngine(readText, null);
我尝试将“readText”传递给规则引擎却给了我以下异常?
Newtonsoft.Json.JsonSerializationException: 'Unexpected end when reading JSON. Path '', line 1, position 1.'
异常发生在这一行:var re = new RulesEngine.RulesEngine(readText, null);
- 我使用在线 JSON 检查了 JSON 是否有效 验证器。
- 我还尝试在顶部添加花括号和 底部。
- 我什至尝试从 文档在这里 https://github.com/microsoft/RulesEngine#how-to-use-it(知道 它不起作用,但至少应该通过创建 RulesEngine),但同样的错误也失败了。
【问题讨论】:
-
最好提供静态方法RulesEngine.RulesEngine(的代码
-
@RomanIeromenko:这是他们正在使用的库的一部分。它位于github.com/microsoft/RulesEngine/blob/main/src/RulesEngine/…,但 OP 不知道这一点并非完全不合理。
-
抱歉伙计们,我应该提到在我的代码 sn-p 等中使用该库的位置。
标签: c# .net-core rule-engine jsonserializer