[WEBGL] Post json - complicated structure
Good Day ,
I have problem with sending json data. When i have simple structure like:
{
"email": "string",
"password": "string"
}
its not a problem. I can use :
WWWForm wwwForm = new WWWForm ();
wwwForm.AddField ("email", login);
wwwForm.AddField ("password", password);
WWW www = new WWW (baseURL+loginURL, wwwForm);
yield return www;
and its working. But i dont know what to do when i have structure like this:
{
"resource": [
{
"user_id": 0,
"name": "string",
"value": "string"
}
]
}
I was trying by www class and by UnityWebRequest and no success.... Can anyone help me? Show me the way to the light :)
EDIT. SOLUTION::: I found solution for my problem:
string json =
"{'resource':["+
"{" +
"'BoatName':'" + boatName + "'," +
"'BoatType':'" + boatType + "'," +
"'BoatColorTop':'" + boatColorTop + "'," +
"'BoatColorBottom':'" + boatColorBottom + "'," +
"'BoatColorStripe':'" + boatColorStripe + "'," +
"'TowerType':'" + towerType + "'," +
"'TowerColor':'" + towerColor + "'," +
"'Engine':'" + engine + "'," +
"'Package':'" + package + "'" +
"}]}";
json = json.Replace("'","\"");
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add (apiKeyHeader, apiKey);
headers.Add (sesionTokenHeader, sesionToken);
headers.Add ("Content-Type", "application/json");
byte[] body = Encoding.ASCII.GetBytes(json);
WWW www = new WWW (baseURL + dataBaseURL, body, headers);
yield return www;
var result = JSON.Parse (www.text);
print ("Success: " + result);
Comment
Your answer
Follow this Question
Related Questions
WWW Class silent crach 1 Answer
Refresh Chat room messages 1 Answer
Can WWW return a JOSN string? 0 Answers
How to load textures on run-time for a game that is built for WebGL 0 Answers