-2
我正在嘗試調用Web服務並獲取json響應以訪問我的應用程序。我爲JSON響應的get set屬性創建了類。下面是我試圖從C#控制檯應用程序調用Web服務
public class iResponse
{
public iResponse(){ }
public List<iDTO> data { get; set; }
}
public class iDTO
{
public iDTO() { }
public class Field
{
public string label { get; set; }
public string type { get; set; }
public string name { get; set; }
}
public class CForm
{
public int id { get; set; }
public string name { get; set; }
public string note { get; set; }
public List<Field> fields { get; set; }
}
public class IlMetadata
{
}
public class IlResponse
{
public List<CustomForm> custom_forms { get; set; }
public IlMetadata il_metadata { get; set; }
}
public class RootObject
{
public IlResponse il_response { get; set; }
}
,並試圖調用服務像下面
public class iAPICall
{
string BaseURL= ConfigurationManager.AppSettings["BaseURL"];
string accessToken = ConfigurationManager.AppSettings["AccessToken"];
public void Get()
{
using (var iab = new HttpClient())
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
Uri uri = new Uri(BaseURL);
iab.BaseAddress = uri;
iab.DefaultRequestHeaders.Accept.Clear();
iab.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
iab.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
var response = iab.GetAsync(BaseURL).Result;
在這裏,我需要得到來自服務調用的響應,並將它們存儲到字符串。像字符串中每個字段的響應一樣。我應該如何繼續下去。
這裏的結果將存儲整個響應,但如何從響應中獲取每個字段。我們需要反序列化它嗎? – user4912134
是的,你必須反序列化它,而不是一個json字符串 – PMerlet