나는 디자이너의 텍스트 상자에 데이터를 소비하고 구문 분석하려고 시도한 PHP 웹 서비스가 있습니다 (Windows 10 앱 스토어 응용 프로그램에서 작업), 이것은 내 코드입니다.
public sealed partial class MainPage : Page
{
public string uriString = "my URL";
public MainPage()
{
this.InitializeComponent();
Getdata();
}
private async void Getdata()
{
var http = new HttpClient();
http.MaxResponseContentBufferSize = Int32.MaxValue;
System.Collections.ArrayList response = new System.Collections.ArrayList(new string[] { await http.GetStringAsync(uriString) });
var rootObject = JsonConvert.DeserializeObject<Sponsorises.RootObject>(response); //the error is here
sponsorname.Text = rootObject.nom; //the name of my textBox
}
public class Sponsorises
{
internal class RootObject
{
public string nom { get; set; }
public string tel { get; set; }
public string photo { get; set; }
public string sponsorise_adrs { get; set; }
}
}
이것은 내 json 코드입니다.
{
success: 1,
message: "sponsorise found!",
total: 1,
sponsorises: [
{
nom: "my third local",
tel: "88888888",
photo: "http://192.168.1.1/1446241709_ab_cart2_bleu2.png",
sponsorise_adrs: "the adress"
}
]
}
arraylist 응답을 문자열 rootObject로 변환하는 데 문제가 있습니다. 도움을 주셔서 감사합니다.
다음에 대해 다른 클래스를 추가 할 수 있습니다 sponsorises
.
internal class RootObject
{
public string success { get; set; }
public string message { get; set; }
public string total { get; set; }
public List<Sponsorise> sponsorises { get; set; }
}
class Sponsorise
{
public string nom { get; set; }
public string tel { get; set; }
public string photo { get; set; }
public string sponsorise_adrs { get; set; }
}
그리고 다음과 같이 deserialize하십시오.
var rootObject = JsonConvert.DeserializeObject<RootObject>(response);
sponsorname.Text = rootObject.sponsorises[0].nom;
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다