【问题标题】:Parse json string provided as input parameter for exe C#解析作为 exe C# 的输入参数提供的 json 字符串
【发布时间】:2018-09-17 12:53:19
【问题描述】:

您好,我有一个应用程序需要从运行命令执行:

D:\MyApplication.exe {\"mydllpath\":\"D:\\dll\",\"FilePath\":\"D:\\Input\\abc.doc\", \"Attribute\":\"word\"}

但是,我无法提取“mydllpath”、“FilePath”和“Attribute”中的值,解析时显示错误。

错误:加载 JObject 时内容意外结束。路径“mydllpath”,第 3 行,位置 0。 代码:

foreach (string arg in args)
{
    var x = JObject.Parse(arg);

任何帮助将不胜感激!

【问题讨论】:

    标签: c# json parsing


    【解决方案1】:

    如果转义 JSON,则需要将其括在字符串中

    D:\MyApplication.exe "{\"mydllpath\":\"D:\dll\",\"FilePath\":\"D:\Input\abc.doc\", \"Attribute\":\"word\"}"
    

    将在代码中接收为

    {"mydllpath":"D:\dll", "FilePath":"D:\Input\abc.doc", "Attribute":"word"}
    

    并允许正确解析。

    var json = args[0];
    var x = JObject.Parse(json);
    

    【讨论】:

      猜你喜欢
      • 2019-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-02
      • 2012-11-23
      • 1970-01-01
      • 1970-01-01
      • 2019-05-17
      相关资源
      最近更新 更多