Newtonsoft.Json works in Unity Editor but not on mobile devices
I am programming a game of questions and answers by categories in Unity. The categories are obtained through a PHP script that returns a JSON text, when I use this solution in the UnityEditor it works correctly, but when I install the .apk on my mobile device, deserialization does not work.
The connection to the mysql database and the PHP scripts work correctly because before I log in and it works fine
string json = [
{ "id_cat":"1",
"nombre_cat":"DAM",
"id_cat_padre":"0"
},
{ "id_cat":"4",
"nombre_cat":"ASIR",
"id_cat_padre":"0"
},
{ "id_cat":"5",
"nombre_cat":"DAW",
"id_cat_padre":"0"
}
]
then I convert this string to a List of Categories
lsSubCategorias = JsonConvert.DeserializeObject<List<Categoria>>(json, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
I've put traces in the code and it's right on that line where it stops.
I Installed the Newtonsoft.Json using the NuGet and it appears in the references.
The problem is that it works in Unity Editor but it doesn't work on my android device
I've also dealt with only one category object instead of a list, but it doesn't work either. And it is not a visualization problem because I have created category objects and created buttons with them.
Answer by Larry-Dietz · Dec 06, 2019 at 12:39 AM
I recently had the exact same problem, I got it working by using JSON.NET for Unity from the asset store.
It's a free asset.
It should get you working as expected. It actually uses a version of NewtonSoft.Json