c# - Firebase Android: Child JSON array not being serialized properly on Android 4.2.2 -
i serializing party object looks this:
public class party { public long lastping; public string id; public int ownerid; public list<partyplayer> players; public int status; public long created; public long lastserverupdate; public int balance; public int size; public partycharacter character; public string mmcid; }
normally, formatted json object (look @ players object, regular object array):
{"id":"key_test","players":[{"character":{"level":9,"visibleitems":[4,0,0],"id":970,"experience":54000,"type":1,"visibleskills":[1,2,3]},"name":"wizard428","lastping":1461555298086,"id":428}]}
however, when run same code on android 4.2.2, players object not valid json array, instead, array serialized giant string:
{"id":"key_test","players":"[{id=467, lastping=1461555567191, name=dragonfly467, character={id=1049, experience=0, visibleskills=[1, 2, 3], level=1, visibleitems=[4, 0, 0], type=1}}]"}
here's c# wrapper gets value firebase:
public string stringvalue { { androidjavaobject javaobject = getjavaobject ().call<androidjavaobject> ("getvalue"); return javaobject != null ? javaobject.call<string> ("tostring") : string.empty; } }
the code i'm using super straight forward , looks this:
public void addorupdateparty(dictionary<string,object> d) { string dser = jsonconvert.serializeobject (d); debug.log ("serialized object: " + dser); }
temporary workaround:
i wrote temporary workaround creating following methods adds double quotes object supposed string make parsable json.net. if you're using this, add string values 3rd line in string array.
class jsoneditor { public static string recursivequotes(string s) { string[] stringify = new string[]{ "id","name", "mmcid", "currentmatch"}; // have add search terms because strings can contain int values , impossible identify checking value. string searchterm = null; foreach(string check in stringify) { if (s.contains (check+"=")) { // replace = :, check+= confirmation there untouched strings. searchterm = check; } } if (searchterm != null) { // find search term , value follows it, replace value string quotes string searcharea = s.split(new string[]{searchterm+"="}, stringsplitoptions.none)[1]; string value = searcharea.split (',') [0]; if(value.contains("}")) { value = searcharea.split('}')[0]; } string replaceterm = searchterm + "=" + value; string newterm = searchterm + ":\"" + value + "\""; s = s.replace (replaceterm, newterm); return recursivequotes (s); } else { return s.replace("=",":").replace("\"[", "[").replace("]\"", "]"); } return s; } }
now can do:
jsonconvert.deserializeobject<party> (jsoneditor.recursivequotes(d));
thanks!
Comments
Post a Comment