Note:不知道为什么通过Txt读取的JsonString,如果TXT 不是ANSI编码的话,会报JsonArrayStringToUStruct Unable to parse。
bool UWgtCpp_BaseMain::Http_readSortList() { auto temp_request = UNetAPI::createRequst(TEXT("http://localhost:59754/StudentService.svc/GetStudentList"), TEXT("GET")); temp_request->OnProcessRequestComplete().BindUObject(this, &UWgtCpp_BaseMain::OnArrSortListLoaded); temp_request->ProcessRequest(); return true; } void UWgtCpp_BaseMain::OnArrSortListLoaded(FHttpRequestPtr _request, FHttpResponsePtr _response, bool bWasSuccessful) { UE_LOG(LogTemp, Warning, TEXT("OnArrSortListLoaded")); if (bWasSuccessful) { switch (_response->GetResponseCode()) { case 200: TArray<FDataCpp_BaseSortItem> arr; FJsonObjectConverter::JsonArrayStringToUStruct<FDataCpp_BaseSortItem>(_response->GetContentAsString(), &arr, 0,0); for (auto item : arr) { auto temp_str = FString::Printf(TEXT("%d , %s"),item.id , item.Name); GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Cyan, item.Name); } break; } } }
[OperationContract] [WebInvoke ( Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetStudentList" ) ] IList<Student> GetStudentList();
[{"Id":1,"Name":"sad"},{"Id":2,"Name":"ttt"},{"Id":3,"Name":"tretre"},{"Id":4,"Name":"terter"},{"Id":5,"Name":"treter"},{"Id":6,"Name":"fsdfds"},{"Id":7,"Name":"cccc"},{"Id":8,"Name":"vvvv"},{"Id":9,"Name":"bbb"},{"Id":10,"Name":"nnn"},{"Id":11,"Name":"mm"},{"Id":12,"Name":"qqq"},{"Id":13,"Name":"www"},{"Id":14,"Name":"eee"},{"Id":15,"Name":"rrr"},{"Id":16,"Name":"ttt"},{"Id":17,"Name":"yyy"},{"Id":18,"Name":"uuu"},{"Id":19,"Name":"iii"},{"Id":20,"Name":"ooo"},{"Id":21,"Name":"ppp"},{"Id":22,"Name":"aaa"},{"Id":23,"Name":"sss"},{"Id":24,"Name":"ddd"},{"Id":25,"Name":"fff"}]