我需要在C#应用程序中解析JSON数组。 JSON的格式示例如下:
idx <- which(adist(dt$words,dt2$words) < 2, arr.ind = T)
dt$match <- (dt$words %in% dt2$words[idx[,2]])
#> dt
# id words match
#1 0 weg TRUE
#2 0 verte TRUE
#3 0 spiegelend TRUE
#4 0 spiegeld FALSE
#5 0 einde FALSE
#6 0 spiegel FALSE
#7 0 spiegelende FALSE
#8 1 weg TRUE
#9 1 spiegelend TRUE
#10 1 asfalt FALSE
#11 1 fata FALSE
#12 1 morgana FALSE
这是我的解析代码:
dt <- structure(list(id = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L),
words = c("weg", "verte", "spiegelend", "spiegeld", "einde", "spiegel", "spiegelende", "weg", "spiegelend", "asfalt", "fata", "morgana")),
.Names = c("id", "words"), row.names = c(NA, -12L), class = c("data.table", "data.frame"))
dt2 <- structure(list(id = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L),
words = c("hoe", "komt", "het", "dat", "de", "weg", "in", "de", "verte", "soms", "spiegelend", "lijkt")),
.Names = c("id", "words"), row.names = c(NA, -12L), class = c("data.table", "data.frame"))
我无法创建名为“event”的参数,因为它是关键字。
如何解析数组或创建名为“event”的参数?
答案 0 :(得分:1)
您应该遵循c#编码指南:
public class Response
{
public MatchEvent Event { get; set; }
}
然后,如果您使用的是Json.NET(在较新的MS框架中使用),您可以设置格式化程序。 例如,在WebAPI中:
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
请参阅此问题:How can I return camelCase JSON serialized by JSON.NET from ASP.NET MVC controller methods?
答案 1 :(得分:0)
有一些常见的方法可以读取Json数据。您可以使用Dictionary<object,object>
读取数据,然后使用<key,value>
对来获取数据,从而解析json数据。