my json code :
{
"vuser": {
"id": "1",
"email": "mohsensd1373@gmail.com ",
"tel": "000000",
"fname": "kingblack",
"username": "mohsensd1373",
"password": "000000",
"nfarm": "mohsensd1373"
},
"vfarms": {
"id": "1",
"name": "mohsensd1373",
"gift": "0",
"Planting": "10",
"power": "0"
},
"vPlanting": [
{
"id": "1",
"nfarm": "mohsensd1373",
"type": "flower",
"sprite": "flower",
"timer": "60",
"result": "flower",
"posx": "1",
"posy": "1"
},
{
"id": "2",
"nfarm": "mohsensd1373",
"type": "flower",
"sprite": "flower",
"timer": "60",
"result": "flower",
"posx": "2",
"posy": "2"
}
]
}
this code for get json from url and convert to class object:
using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;
class httprequest : MonoBehaviour
{
void Start() { }
public string GET(string url)
{
RootObject myObject = new RootObject();
StartCoroutine(GetText(url, (result) =>{
PlayerPrefs.SetString("sdall", result);
//Debug.Log(result);
}));
Debug.Log(PlayerPrefs.GetString("sdall"));
myObject = JsonUtility.FromJson<RootObject>(PlayerPrefs.GetString("sdall"));
Debug.Log(myObject.vuser.email);
return myObject.vuser.email;
}
[Serializable]
public class VUser
{
public string id { get; set; }
public string email { get; set; }
public string tel { get; set; }
public string fname { get; set; }
public string username { get; set; }
public string password { get; set; }
public string nfarm { get; set; }
}
public class VFarms
{
public string id { get; set; }
public string name { get; set; }
public string gift { get; set; }
public string Planting { get; set; }
public string power { get; set; }
}
public class VPlanting
{
public string id { get; set; }
public string nfarm { get; set; }
public string type { get; set; }
public string sprite { get; set; }
public string timer { get; set; }
public string result { get; set; }
public string posx { get; set; }
public string posy { get; set; }
}
public class RootObject
{
public VUser vuser { get; set; }
public VFarms vfarms { get; set; }
public List<VPlanting> vPlanting { get; set; }
}
IEnumerator GetText(string url, Action<string> result)
{
UnityWebRequest www = UnityWebRequest.Get(url);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
if (result != null)
result(www.error);
}
else
{
//Debug.Log(www.downloadHandler.data);
if (result != null)
result(www.downloadHandler.text);
}
}
}
returned this error:
ArgumentException: JSON parse error: Invalid escape character in string.
UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) (at <1386288601af43018501cce2912f52f4>:0)
UnityEngine.JsonUtility.FromJson[T] (System.String json) (at <1386288601af43018501cce2912f52f4>:0)
httprequest.GET (System.String url) (at Assets/myscript 1/httprequest.cs:21)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <437ba245d8404784b9fbab9b439ac908>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <437ba245d8404784b9fbab9b439ac908>:0)
FlowCanvas.Nodes.PureReflectedMethodNode.Call () (at Assets/ParadoxNotion/FlowCanvas/Modules/FlowGraphs/Nodes/Functions/Reflected/Internal/Method/PureReflectedMethodNode.cs:54)
FlowCanvas.Nodes.PureReflectedMethodNode+<>c__DisplayClass12_1.<RegisterPorts>b__2 (FlowCanvas.Flow flow) (at Assets/ParadoxNotion/FlowCanvas/Modules/FlowGraphs/Nodes/Functions/Reflected/Internal/Method/PureReflectedMethodNode.cs:80)
FlowCanvas.FlowOutput.Continue (FlowCanvas.Flow f) (at Assets/ParadoxNotion/FlowCanvas/Modules/FlowGraphs/Ports.cs:272)
UnityEngine.Logger:LogException(Exception)
ParadoxNotion.Services.Logger:ForwardToUnity(LogType, Object, String, Object) (at Assets/ParadoxNotion/CanvasCore/Common/Runtime/Services/Logger.cs:114)
ParadoxNotion.Services.Logger:Internal_Log(LogType, Object, String, Object) (at Assets/ParadoxNotion/CanvasCore/Common/Runtime/Services/Logger.cs:108)
ParadoxNotion.Services.Logger:LogException(Exception, String, Object) (at Assets/ParadoxNotion/CanvasCore/Common/Runtime/Services/Logger.cs:66)
NodeCanvas.Framework.Node:Error(Object) (at Assets/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/Node.cs:326)
FlowCanvas.FlowOutput:Continue(Flow) (at Assets/ParadoxNotion/FlowCanvas/Modules/FlowGraphs/Ports.cs:276)
FlowCanvas.FlowOutput:Call(Flow) (at Assets/ParadoxNotion/FlowCanvas/Modules/FlowGraphs/Ports.cs:250)
FlowCanvas.Nodes.StartEvent:OnStartCallback() (at Assets/ParadoxNotion/FlowCanvas/Modules/FlowGraphs/Nodes/Events/Graph/StartEvent.cs:33)
NodeCanvas.Framework.GraphOwner:InvokeStartEvent() (at Assets/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/GraphOwner.cs:384)
NodeCanvas.Framework.GraphOwner:Start() (at Assets/ParadoxNotion/CanvasCore/Framework/Runtime/Graphs/GraphOwner.cs:375)