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,]
c# rest unity3d post get
New contributor
|
show 5 more comments
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,]
c# rest unity3d post get
New contributor
1
Get the text version:www.downloadHandler.text
instead ofwww.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
|
show 5 more comments
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,]
c# rest unity3d post get
New contributor
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
c# rest unity3d post get
New contributor
New contributor
edited Nov 17 at 22:32
New contributor
asked Nov 17 at 22:04
jakkis
64
64
New contributor
New contributor
1
Get the text version:www.downloadHandler.text
instead ofwww.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
|
show 5 more comments
1
Get the text version:www.downloadHandler.text
instead ofwww.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
|
show 5 more comments
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.
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
jakkis is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Get the text version:
www.downloadHandler.text
instead ofwww.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