x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

HTTP通信について

初めまして。 昨日から触り始めたUE4初心者です。

さっそく質問なのですが、 HTTP通信をして、JSONの値を取得しようとしているのですが、そもそもどういったBluePrintを使う必要があるのでしょうか?

どなたか教えていただけると助かります。

Product Version: Not Selected
Tags:
more ▼

asked Apr 17 '14 at 09:41 AM in Japanese

avatar image

ssdkfk
10 8 9 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

HTTP通信は対応されています。参考になるスレッドの幾つかがあります:

Making HTTP calls

Best way to perform a http request?

そしてJSONファイルの読み込みはTJsonReaderとTJsonWriterというクラスがありますので、それをご覧ください。

ひとつの例として下記のコードが100個のある配列を生成してHTTPで送ります:

 FString Payload;
     TSharedRef< TJsonWriter<TCHAR, TCondensedJsonPrintPolicy<TCHAR> > > JsonWriter = TJsonWriterFactory<TCHAR, TCondensedJsonPrintPolicy<TCHAR> >::Create(&Payload);
     JsonWriter->WriteObjectStart();
     JsonWriter->WriteArrayStart(TEXT("Entries"));
     // write 100 entries
     for (int32 Idx = 0; Idx < 100; Idx++)
     {
         JsonWriter->WriteObjectStart();
         JsonWriter->WriteValue(TEXT("Idx"), Idx);
         JsonWriter->WriteValue(TEXT("Name"), TEXT("SomeName"));
         JsonWriter->WriteObjectEnd();
     }
     JsonWriter->WriteArrayEnd();
     JsonWriter->WriteObjectEnd();
     JsonWriter->Close();
 
     TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
     HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
     HttpRequest->SetURL(TEXT("https://somehost.com/somepath?param1&param2"));
     HttpRequest->SetVerb(TEXT("POST"));
     HttpRequest->SetContentAsString(Payload);
     HttpRequest->OnProcessRequestComplete().BindRaw(this, &HttpCompleteCallback);
     HttpRequest->ProcessRequest();

よろしくお願いします!

more ▼

answered Apr 25 '14 at 02:32 AM

avatar image

Joe Conley STAFF
361 39 5 18

avatar image ssdkfk Apr 25 '14 at 02:52 AM

おおおー!どうもありがとう!!助かります!!! さっそく試してみます!

avatar image ssdkfk Apr 25 '14 at 07:39 AM

こんにちは。

試しにいただいたコードの上から2行だけをコードに追加してビルドをしてみましたが、ビルドは通りませんでした。 コードは以下のようにしているのですが、何が問題なのでしょう?

 #include "BasicClass.h"
 #include "HelloworldPrinter.h"
 
 
 AHelloworldPrinter::AHelloworldPrinter(const class FPostConstructInitializeProperties& PCIP)
     : Super(PCIP)
 {
     MyNumber = 12;
 }
 
 void AHelloworldPrinter::BeginPlay(){
     Super::BeginPlay();
 
     if (GEngine){
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HelloWorld!"));
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::FromInt(MyNumber));
     }
     
 
     FString Payload;
     TSharedRef< TJsonWriter<TCHAR, TCondensedJsonPrintPolicy<TCHAR> > > JsonWriter = TJsonWriterFactory<TCHAR, TCondensedJsonPrintPolicy<TCHAR> >::Create(&Payload);
     
 
 }
avatar image ssdkfk May 01 '14 at 07:40 AM

解決しました! コードは以下にまとめておきました。 http://nextdeveloper.hatenablog.com/entry/2014/05/01/163422

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question