這是那些日子之一;我設法解決了2個問題,但我不知道如何解決第三個錯誤。不能隱式轉換類型'Newtonsoft.Json.Linq.JObject'
我需要返回JSON對象,但我得到以下錯誤:
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?)
誰能幫我解決這個錯誤?
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;
}
而是問同一個問題多次,我會發布JSON字符串並問*我做錯了什麼?* – I4V
嗨I4V,我解決了問題與其他2個職位我當時是在我的mvc控制器,直到我把代碼移動到類th在這個錯誤發生。 – CareerChange
CareerChange,很高興知道你解決了你的問題。 – I4V