Json 使用 C# 和 Mono
Json with C# and Mono
我正在尝试将 json 字符串读入内存并获取此未记录的错误消息
$ mcs -r:FortnoxAPILibrary.dll -r:npgsql.dll -r:System.Data.dll -r:Newtonsoft.Json.dll Vouchers.cs
Vouchers.cs(44,18): error CS0103: The name `JArray' does not exist in the current context
Compilation failed: 1 error(s), 0 warnings
我的密码是
var json = System.IO.File.ReadAllText("test.json");
var objects = JArray.Parse(json); // parse as array
foreach(JObject root in objects)
{
foreach(KeyValuePair<String, JToken> app in root)
{
var appName = app.Key;
var description = (String)app.Value["Description"];
var value = (String)app.Value["Value"];
Console.WriteLine(appName);
Console.WriteLine(description);
Console.WriteLine(value);
Console.WriteLine("\n");
}
}
在哪里记录了它应该如何工作?
没有记录我必须包含这一行。
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
您很可能遗漏了 using 语句。
using Newtonsoft.Json.Linq;
您编写的每段 C# 代码(核心类型除外)都需要一个指向任何依赖项的 using 语句。
C# 库通常不记录代码块的 using 语句要求。也许是疏忽,但大多数用户都在使用 IDE,它会警告缺少语句并提供自动插入语句的选项。
我正在尝试将 json 字符串读入内存并获取此未记录的错误消息
$ mcs -r:FortnoxAPILibrary.dll -r:npgsql.dll -r:System.Data.dll -r:Newtonsoft.Json.dll Vouchers.cs
Vouchers.cs(44,18): error CS0103: The name `JArray' does not exist in the current context
Compilation failed: 1 error(s), 0 warnings
我的密码是
var json = System.IO.File.ReadAllText("test.json");
var objects = JArray.Parse(json); // parse as array
foreach(JObject root in objects)
{
foreach(KeyValuePair<String, JToken> app in root)
{
var appName = app.Key;
var description = (String)app.Value["Description"];
var value = (String)app.Value["Value"];
Console.WriteLine(appName);
Console.WriteLine(description);
Console.WriteLine(value);
Console.WriteLine("\n");
}
}
在哪里记录了它应该如何工作?
没有记录我必须包含这一行。
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
您很可能遗漏了 using 语句。
using Newtonsoft.Json.Linq;
您编写的每段 C# 代码(核心类型除外)都需要一个指向任何依赖项的 using 语句。
C# 库通常不记录代码块的 using 语句要求。也许是疏忽,但大多数用户都在使用 IDE,它会警告缺少语句并提供自动插入语句的选项。