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

above are the classes i am using to deserialize the json response being received by calling the alchemy API.

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;

I am getting this error:

An exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll but was not handled in user code

Additional information: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.

Community
  • 1
  • 1
Kanwal
  • 75
  • 1
  • 2
  • 10
  • 1
    Please fix the code formatting – Sebastian Negraszus Aug 17 '15 at 13:22
  • i have fixed the code formatting – Kanwal Aug 17 '15 at 13:28
  • Can you please post the data that is sent to the service? – Johan Brännmar Aug 17 '15 at 13:37
  • "status": "OK", "usage": "By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html", "totalTransactions": "1", "language": "english", "keywords": [ { "relevance": "0.951162", "text": "homeland" }, { "relevance": "0.814847", "text": "pakistan" }, { "relevance": "0.580087", "text": "country" } ] – Kanwal Aug 17 '15 at 13:46

1 Answers1

0

i was making an error in url. url was "https://alchemy.p.mashape.com/text/TextGetRankedKeywords?outputMode=json&text=" moreover i was required to make array instance of keywords object in JsonData class

Kanwal
  • 75
  • 1
  • 2
  • 10