【问题标题】:Unexpected character encountered while parsing value: <. Path '', line 0, position 0. while calling alchemy api through mashape解析值时遇到意外字符:<。路径'',第 0 行,第 0 位置。同时通过 mashape 调用 alchemy api
【发布时间】:2015-08-17 13:22:19
【问题描述】:
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.dll 中出现“Newtonsoft.Json.JsonReaderException”类型的异常,但未在用户代码中处理

附加信息:解析值时遇到意外字符:

【问题讨论】:

  • 请修正代码格式
  • 我已经修复了代码格式
  • 能否请您发布发送到服务的数据?
  • "status": "OK", "usage": "通过访问 AlchemyAPI 或使用 AlchemyAPI 生成的信息,即表示您同意遵守 AlchemyAPI 使用条款:alchemyapi.com/company/terms.html", " totalTransactions": "1", "language": "english", "keywords": [ { "relevance": "0.951162", "text": "homeland" }, { "relevance": "0.814847", "text" :“巴基斯坦”},{“相关性”:“0.580087”,“文本”:“国家”}]

标签: c# .net json api alchemy


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-07-25
    • 2015-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多