Note:如果通过Txt读取的JsonString,如果TXT 不是ANSI编码的话,会报JsonArrayStringToUStruct Unable to parse。(4.13出,不知道是不是我电脑的个例)
Build.cs 包含 JsonUtilities 模块。
UE4:
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 :
TArray<FDataCpp_BaseSortItem> arr; FJsonObjectConverter::JsonArrayStringToUStruct<FDataCpp_BaseSortItem>(_response->GetContentAsString(), &arr, ,); for (auto item : arr)
{
auto temp_str = FString::Printf(TEXT("%d , %s"),item.id , item.Name);
GEngine->AddOnScreenDebugMessage(-, 5.0f, FColor::Cyan, item.Name);
} break;
}
}
}
WCF:
[OperationContract]
[WebInvoke
(
Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "GetStudentList"
)
]
IList<Student> GetStudentList();
*.JSON
[{"Id":,"Name":"sad"},{"Id":,"Name":"ttt"},{"Id":,"Name":"tretre"},{"Id":,"Name":"terter"},{"Id":,"Name":"treter"},{"Id":,"Name":"fsdfds"},{"Id":,"Name":"cccc"},{"Id":,"Name":"vvvv"},{"Id":,"Name":"bbb"},{"Id":,"Name":"nnn"},{"Id":,"Name":"mm"},{"Id":,"Name":"qqq"},{"Id":,"Name":"www"},{"Id":,"Name":"eee"},{"Id":,"Name":"rrr"},{"Id":,"Name":"ttt"},{"Id":,"Name":"yyy"},{"Id":,"Name":"uuu"},{"Id":,"Name":"iii"},{"Id":,"Name":"ooo"},{"Id":,"Name":"ppp"},{"Id":,"Name":"aaa"},{"Id":,"Name":"sss"},{"Id":,"Name":"ddd"},{"Id":,"Name":"fff"}]