码迷,mamicode.com
首页 > Web开发 > 详细

UE4 WCF RestFul 服务器 读取JSON 数据并解析 简单实例

时间:2016-01-15 12:43:22      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

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"}]

 

UE4 WCF RestFul 服务器 读取JSON 数据并解析 简单实例

标签:

原文地址:http://www.cnblogs.com/linqing/p/5132834.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!