Unity 3D how to get/post a list from REST API











up vote
0
down vote

favorite












Im having a problem with get/post a list from/to REST server with Unity 3D and C#.



My server:



from flask import Flask, jsonify
import requests, json

app = Flask(__name__)
url = "http://0.0.0.0:5000/"
list = ["1","2","3","4"]


@app.route('/')
def index():
return "Hello"
@app.route('/list', methods=['GET'])
def get_tasks():
return jsonify(list)
if __name__ == '__main__':
app.run(host="0.0.0.0", port = 5000,debug=True)


How do i Download the list of objects in Unity and save it to a variable? Also how do i post/update another list? https://docs.unity3d.com/Manual/UnityWebRequest-CreatingDownloadHandlers.html



with this tutorial i got the "Hello" text returnet but it only returns "1" when using



byte results = www.downloadHandler.data;
Debug.Log(results)


edit: my Python client:



import json 
import requests

list = " "
api_url = 'http://ipaddress:5000/list/'
r = requests.get(url = api_url, json=list)
a = r.content

if "3" in a:
print "found"


When client is ran, it prints "found" so it returns the wole list. in Unity i get: [1,]










share|improve this question









New contributor




jakkis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Get the text version: www.downloadHandler.text instead of www.downloadHandler.data
    – Programmer
    Nov 17 at 22:14










  • Works the same way, i only get the first value on the list
    – jakkis
    Nov 17 at 22:15










  • Then that's what the sever is sending. On your server, try to log the data you're sending.
    – Programmer
    Nov 17 at 22:16












  • The server sends the whole list, atleast it does to my python client.
    – jakkis
    Nov 17 at 22:18










  • Edit your question and post what the python client is getting. Now, add what Unity is getting. Finally, if you don't mind share the url you're making the request to
    – Programmer
    Nov 17 at 22:20















up vote
0
down vote

favorite












Im having a problem with get/post a list from/to REST server with Unity 3D and C#.



My server:



from flask import Flask, jsonify
import requests, json

app = Flask(__name__)
url = "http://0.0.0.0:5000/"
list = ["1","2","3","4"]


@app.route('/')
def index():
return "Hello"
@app.route('/list', methods=['GET'])
def get_tasks():
return jsonify(list)
if __name__ == '__main__':
app.run(host="0.0.0.0", port = 5000,debug=True)


How do i Download the list of objects in Unity and save it to a variable? Also how do i post/update another list? https://docs.unity3d.com/Manual/UnityWebRequest-CreatingDownloadHandlers.html



with this tutorial i got the "Hello" text returnet but it only returns "1" when using



byte results = www.downloadHandler.data;
Debug.Log(results)


edit: my Python client:



import json 
import requests

list = " "
api_url = 'http://ipaddress:5000/list/'
r = requests.get(url = api_url, json=list)
a = r.content

if "3" in a:
print "found"


When client is ran, it prints "found" so it returns the wole list. in Unity i get: [1,]










share|improve this question









New contributor




jakkis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Get the text version: www.downloadHandler.text instead of www.downloadHandler.data
    – Programmer
    Nov 17 at 22:14










  • Works the same way, i only get the first value on the list
    – jakkis
    Nov 17 at 22:15










  • Then that's what the sever is sending. On your server, try to log the data you're sending.
    – Programmer
    Nov 17 at 22:16












  • The server sends the whole list, atleast it does to my python client.
    – jakkis
    Nov 17 at 22:18










  • Edit your question and post what the python client is getting. Now, add what Unity is getting. Finally, if you don't mind share the url you're making the request to
    – Programmer
    Nov 17 at 22:20













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Im having a problem with get/post a list from/to REST server with Unity 3D and C#.



My server:



from flask import Flask, jsonify
import requests, json

app = Flask(__name__)
url = "http://0.0.0.0:5000/"
list = ["1","2","3","4"]


@app.route('/')
def index():
return "Hello"
@app.route('/list', methods=['GET'])
def get_tasks():
return jsonify(list)
if __name__ == '__main__':
app.run(host="0.0.0.0", port = 5000,debug=True)


How do i Download the list of objects in Unity and save it to a variable? Also how do i post/update another list? https://docs.unity3d.com/Manual/UnityWebRequest-CreatingDownloadHandlers.html



with this tutorial i got the "Hello" text returnet but it only returns "1" when using



byte results = www.downloadHandler.data;
Debug.Log(results)


edit: my Python client:



import json 
import requests

list = " "
api_url = 'http://ipaddress:5000/list/'
r = requests.get(url = api_url, json=list)
a = r.content

if "3" in a:
print "found"


When client is ran, it prints "found" so it returns the wole list. in Unity i get: [1,]










share|improve this question









New contributor




jakkis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Im having a problem with get/post a list from/to REST server with Unity 3D and C#.



My server:



from flask import Flask, jsonify
import requests, json

app = Flask(__name__)
url = "http://0.0.0.0:5000/"
list = ["1","2","3","4"]


@app.route('/')
def index():
return "Hello"
@app.route('/list', methods=['GET'])
def get_tasks():
return jsonify(list)
if __name__ == '__main__':
app.run(host="0.0.0.0", port = 5000,debug=True)


How do i Download the list of objects in Unity and save it to a variable? Also how do i post/update another list? https://docs.unity3d.com/Manual/UnityWebRequest-CreatingDownloadHandlers.html



with this tutorial i got the "Hello" text returnet but it only returns "1" when using



byte results = www.downloadHandler.data;
Debug.Log(results)


edit: my Python client:



import json 
import requests

list = " "
api_url = 'http://ipaddress:5000/list/'
r = requests.get(url = api_url, json=list)
a = r.content

if "3" in a:
print "found"


When client is ran, it prints "found" so it returns the wole list. in Unity i get: [1,]







c# rest unity3d post get






share|improve this question









New contributor




jakkis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




jakkis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 17 at 22:32





















New contributor




jakkis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 17 at 22:04









jakkis

64




64




New contributor




jakkis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





jakkis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






jakkis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    Get the text version: www.downloadHandler.text instead of www.downloadHandler.data
    – Programmer
    Nov 17 at 22:14










  • Works the same way, i only get the first value on the list
    – jakkis
    Nov 17 at 22:15










  • Then that's what the sever is sending. On your server, try to log the data you're sending.
    – Programmer
    Nov 17 at 22:16












  • The server sends the whole list, atleast it does to my python client.
    – jakkis
    Nov 17 at 22:18










  • Edit your question and post what the python client is getting. Now, add what Unity is getting. Finally, if you don't mind share the url you're making the request to
    – Programmer
    Nov 17 at 22:20














  • 1




    Get the text version: www.downloadHandler.text instead of www.downloadHandler.data
    – Programmer
    Nov 17 at 22:14










  • Works the same way, i only get the first value on the list
    – jakkis
    Nov 17 at 22:15










  • Then that's what the sever is sending. On your server, try to log the data you're sending.
    – Programmer
    Nov 17 at 22:16












  • The server sends the whole list, atleast it does to my python client.
    – jakkis
    Nov 17 at 22:18










  • Edit your question and post what the python client is getting. Now, add what Unity is getting. Finally, if you don't mind share the url you're making the request to
    – Programmer
    Nov 17 at 22:20








1




1




Get the text version: www.downloadHandler.text instead of www.downloadHandler.data
– Programmer
Nov 17 at 22:14




Get the text version: www.downloadHandler.text instead of www.downloadHandler.data
– Programmer
Nov 17 at 22:14












Works the same way, i only get the first value on the list
– jakkis
Nov 17 at 22:15




Works the same way, i only get the first value on the list
– jakkis
Nov 17 at 22:15












Then that's what the sever is sending. On your server, try to log the data you're sending.
– Programmer
Nov 17 at 22:16






Then that's what the sever is sending. On your server, try to log the data you're sending.
– Programmer
Nov 17 at 22:16














The server sends the whole list, atleast it does to my python client.
– jakkis
Nov 17 at 22:18




The server sends the whole list, atleast it does to my python client.
– jakkis
Nov 17 at 22:18












Edit your question and post what the python client is getting. Now, add what Unity is getting. Finally, if you don't mind share the url you're making the request to
– Programmer
Nov 17 at 22:20




Edit your question and post what the python client is getting. Now, add what Unity is getting. Finally, if you don't mind share the url you're making the request to
– Programmer
Nov 17 at 22:20












1 Answer
1






active

oldest

votes

















up vote
1
down vote













You said that the received data is this format: ["1","2", etc.] and you want the data separated by comma in a List.



First, this is just a text data. Retrieve the text data from www.downloadHandler.text instead of www.downloadHandler.data. Remove the [ and ] then split the final string by comma into array or list.



string results = www.downloadHandler.text;
string trimmed = results.TrimStart('[').TrimEnd(']');
List<string> splitResult = trimmed.Split(',').ToList<string>();


Note that you need to include using System.Linq; at the top of the code in order to use the ToList function above.






share|improve this answer





















  • The last object on the list seems to have the ] bracket still on when i print the splitresult list.
    – jakkis
    Nov 17 at 23:36











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






jakkis is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355971%2funity-3d-how-to-get-post-a-list-from-rest-api%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













You said that the received data is this format: ["1","2", etc.] and you want the data separated by comma in a List.



First, this is just a text data. Retrieve the text data from www.downloadHandler.text instead of www.downloadHandler.data. Remove the [ and ] then split the final string by comma into array or list.



string results = www.downloadHandler.text;
string trimmed = results.TrimStart('[').TrimEnd(']');
List<string> splitResult = trimmed.Split(',').ToList<string>();


Note that you need to include using System.Linq; at the top of the code in order to use the ToList function above.






share|improve this answer





















  • The last object on the list seems to have the ] bracket still on when i print the splitresult list.
    – jakkis
    Nov 17 at 23:36















up vote
1
down vote













You said that the received data is this format: ["1","2", etc.] and you want the data separated by comma in a List.



First, this is just a text data. Retrieve the text data from www.downloadHandler.text instead of www.downloadHandler.data. Remove the [ and ] then split the final string by comma into array or list.



string results = www.downloadHandler.text;
string trimmed = results.TrimStart('[').TrimEnd(']');
List<string> splitResult = trimmed.Split(',').ToList<string>();


Note that you need to include using System.Linq; at the top of the code in order to use the ToList function above.






share|improve this answer





















  • The last object on the list seems to have the ] bracket still on when i print the splitresult list.
    – jakkis
    Nov 17 at 23:36













up vote
1
down vote










up vote
1
down vote









You said that the received data is this format: ["1","2", etc.] and you want the data separated by comma in a List.



First, this is just a text data. Retrieve the text data from www.downloadHandler.text instead of www.downloadHandler.data. Remove the [ and ] then split the final string by comma into array or list.



string results = www.downloadHandler.text;
string trimmed = results.TrimStart('[').TrimEnd(']');
List<string> splitResult = trimmed.Split(',').ToList<string>();


Note that you need to include using System.Linq; at the top of the code in order to use the ToList function above.






share|improve this answer












You said that the received data is this format: ["1","2", etc.] and you want the data separated by comma in a List.



First, this is just a text data. Retrieve the text data from www.downloadHandler.text instead of www.downloadHandler.data. Remove the [ and ] then split the final string by comma into array or list.



string results = www.downloadHandler.text;
string trimmed = results.TrimStart('[').TrimEnd(']');
List<string> splitResult = trimmed.Split(',').ToList<string>();


Note that you need to include using System.Linq; at the top of the code in order to use the ToList function above.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 17 at 23:22









Programmer

74k1077138




74k1077138












  • The last object on the list seems to have the ] bracket still on when i print the splitresult list.
    – jakkis
    Nov 17 at 23:36


















  • The last object on the list seems to have the ] bracket still on when i print the splitresult list.
    – jakkis
    Nov 17 at 23:36
















The last object on the list seems to have the ] bracket still on when i print the splitresult list.
– jakkis
Nov 17 at 23:36




The last object on the list seems to have the ] bracket still on when i print the splitresult list.
– jakkis
Nov 17 at 23:36










jakkis is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















jakkis is a new contributor. Be nice, and check out our Code of Conduct.













jakkis is a new contributor. Be nice, and check out our Code of Conduct.












jakkis is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355971%2funity-3d-how-to-get-post-a-list-from-rest-api%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]