问题
I am trying to deserialize JSON that contains dash (-) characters in some of its property names, by using dynamic types:
string json = MyWebClient.DownloadString("http://api.crossref.org/works/10.1093/brain/75.2.187");
dynamic result = JsonConvert.DeserializeObject<dynamic>(json);
string title = result.message.title[0];
string journal = result.message.container-title[0];
I cannot get the "container-title" value due to use of an illegal character. And I don't want to simply use Replace()
to remove dash characters. Is there any way?
回答1:
Since message
is also a JObject
you can access its properties like a dictionary
result.message["container-title"]
来源:https://stackoverflow.com/questions/36726153/illegal-character-in-property-name-when-serializing-json-to-dynamic