I need to return a json object, but I am getting the following error:
Error 1 Cannot implicitly convert type 'Newtonsoft.Json.Linq.JObject' to 'System.Collections.Generic.IEnumerable<Newtonsoft.Json.Linq.JObject>'. An explicit conversion exists (are you missing a cast?)
Can anyone help me solve this error?
public static IEnumerable<JObject> GetListOfHotels()
{
const string dataPath = "https://api.eancdn.com/ean-services/rs/hotel/v3/list?minorRev=99&cid=55505&apiKey=key&customerUserAgent=Google&customerIpAddress=123.456&locale=en_US¤cyCode=USD&destinationString=washington,united+kingdom&supplierCacheTolerance=MED&arrivalDate=12/12/2013&departureDate=12/15/2013&room1=2&mberOfResults=1&supplierCacheTolerance=MED_ENHANCED";
var request = WebRequest.Create(dataPath);
request.Method = "POST";
const string postData = dataPath;
var byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/json";
request.ContentLength = byteArray.Length;
var dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
var response = request.GetResponse();
var responseCode = (((HttpWebResponse) response).StatusDescription);
var responseStream = response.GetResponseStream();
var responseReader = new StreamReader(responseStream, Encoding.UTF8);
var responseString = responseReader.ReadToEnd();
var root = JObject.Parse(responseString);
return root;
}
The problem is that you are trying to return a JObject
, but because of the current signature of your function, the compiler assumes that it needs a IEnumerable<JObject>
returned.
So you would need to change the signature of your function from expecting an IEnumerable<JObject>
:
public static IEnumerable<JObject> GetListOfHotels()
To accept a JObject
instead:
public static JObject GetListOfHotels()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With