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; }     
}

上記は、alchemy 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.JsonReaderException' の例外が Newtonsoft.Json.dll で発生しましたが、ユーザー コードで処理されませんでした

追加情報: 値の解析中に予期しない文字が検出されました: <。パス ''、行 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 に答える