httpClient = new HttpClient();
stringContent = new HttpStringContent(postBody, UnicodeEncoding.Utf8, "application/json");
httpResponse = await httpClient.PostAsync(uri, stringContent);
String responseString = await httpResponse.Content.ReadAsStringAsync();
編寫UWP應用程序並嘗試將JSON數據發送到Web服務器。在我對象序列化到JSON postBody = JsonConvert.SerializeObject(parentModel);
另一種方法,我得到有效的JSON:HttpStringContent使JSON無效?
"{\"ParentId\":\"[email protected]\",\"ParentPrimaryId\":\"[email protected]\",\"ParentPassword\":\"n78mG2LB18ANtzr7gd2X/fILNELjbjOMuTWbhWoDvcg=\",\"ParentFirstName\":\"Bill\",\"ParentLastName\":\"Gates\",\"AddChildDistrictId\":\"\",\"RemoveChildDistrictId\":\"\",\"ParentToken\":null,\"ParentDistrictId\":\"\",\"ParentChildDistricts\":\"\",\"AppPlatform\":\"Windows 10.0.15063.138\",\"AppVersion\":10000,\"ParentAccountStatus\":1,\"ParentStatusCode\":0,\"ParentFailedSignInAttempt\":0}"
然而,當我通過後身體HttpStringContent,它給了我:
{{"ParentId":"[email protected]","ParentPrimaryId":"[email protected]","ParentPassword":"n78mG2LB18ANtzr7gd2X/fILNELjbjOMuTWbhWoDvcg=","ParentFirstName":"Bill","ParentLastName":"Gates","AddChildDistrictId":"","RemoveChildDistrictId":"","ParentToken":null,"ParentDistrictId":"","ParentChildDistricts":"","AppPlatform":"Windows 10.0.15063.138","AppVersion":10000,"ParentAccountStatus":1,"ParentStatusCode":0,"ParentFailedSignInAttempt":0}}
這是無效的JSON 。這是什麼被髮送?爲什麼它會添加額外的大括號並刪除開頭的引號?
當你說「它給了我」時,它到底是什麼?請解釋你如何得到那個輸出。 –