0
public class keywords
{
   [JsonProperty(PropertyName = "text")]
   public string text { get; set; }
   [JsonProperty(PropertyName = "relevance")]
   public string relevance { get; set; }
}
public class JsonData
{
   [JsonProperty(PropertyName = "status")]
   public string status { get; set; }
   [JsonProperty(PropertyName = "usage")]
   public string usage { get; set; }
   [JsonProperty(PropertyName = "url")]

   public string url { get; set; }
   [JsonProperty(PropertyName = "language")]
   public string language { get; set; }
   [JsonProperty ("keywords")]
   public keywords keyword { get; set; }     
}

以上是我用来反序列化通过调用炼金术 API 接收到的 json 响应的类。

string url =     "https://alchemy.p.mashape.com/Text/TextGetRankedKeywords?outputMode=json&text=" + text;
var response = (Unirest.get("https://alchemy.p.mashape.com/Text/TextGetRankedKeywords?outputMode=json&text=" + text)
   .header("X-Mashape-Key", "AlZVYH30C9mshLPNM7KiE48aFfTHp1h3A31jsnmVPccxBzW5uB")
   .header("Accept", "application/json")
   .asJson<JsonData>()
   .Body);
var status = response.keyword.text;
var score = response.keyword.relevance;

我收到此错误:

Newtonsoft.Json.dll 中出现“Newtonsoft.Json.JsonReaderException”类型的异常,但未在用户代码中处理

附加信息:解析值时遇到意外字符:<。路径 '',第 0 行,第 0 位置。

4

1 回答 1

0

我在 url 中犯了一个错误。url 是“ https://alchemy.p.mashape.com/text/TextGetRankedKeywords?outputMode=json&text= ”此外,我需要在 JsonData 类中创建关键字对象的数组实例

于 2015-08-17T13:44:59.060 回答