JsonFX examples

Do anyone have any handy code using JsonFx. I cannot find any docs or good examples?

thanks

I would like to subscribe to this thread as I’ve been hunting all afternoon for short example of using JsonFX in Unity 3 and I can’t find one anywhere.

What I would like to achieve specifically is:

  • We run a JSON based gaming server which does things like maintain leader boards
  • A sample use of the service would be to post a score: e.g. Player John scores 1000
  • I would like to encode Player Name and Score into a Json object which is posted to the remote server URL
  • The remote Server returns John’s current position and any awards he has won as a json object which I would like to analyse and process in (Unify) Javascript

I’m pretty new to Unity but I’m guessing that the WWW class is the one to use to post and receive the data (even though I’m worried about the security / sandbox restrictions I read about) - The bit I’m struggling with is how to encode and decode the data in and out using JsonFX.

Thanks in advance

Leon

Hey this is done use LitJson, which is a rather old but working Json script(one file only).

The below code communicates with a java server and the protocolparser is some internal wrapping you should ignore.

 IEnumerator generateWTTFiles(){ //IEnumerator
				
		StringBuilder sb = new StringBuilder ();
        JsonWriter writer = new JsonWriter (sb);
		writer.WriteObjectStart ();
		writer.WritePropertyName ("wttids");
        writer.WriteArrayStart ();
	       foreach(int wid in wtts){  
				writer.Write(wid);
			}
		writer.WriteArrayEnd ();
       
		writer.WritePropertyName ("langids");
		writer.WriteArrayStart ();
		int i =0;
		foreach(Realm r in Realm.activeRealms){  
			writer.Write(r.language);
			i++;
		}
		writer.WriteArrayEnd ();
		writer.WriteObjectEnd ();
					
		ProtocolParser chunks = NetworkController.QueryServerForWTT();
		chunks.writeStringChunk(NetworkController.CHUNK_WTT_REQUEST,sb.ToString());
		
		WWW www = new WWW(NetworkController.wttURL.Replace("$REALM$","dk.test.watagame.com"),chunks.send());
		
		yield return www;
		
		if (www.error != null){
			Debug.Log(www.error);				
		}
		ProtocolParser chunksChecker = new ProtocolParser(www.bytes);
		
		string langArr = chunksChecker.getChunkAsString(NetworkController.CHUNK_WTT_RESPONSE);
				JsonData langTable = JsonMapper.ToObject(langArr);	
		
		foreach(Realm r in Realm.activeRealms){
			StreamWriter fileWriter = File.CreateText(Application.dataPath+"/Resources/Languages/"+r.language+".txt");
			
			 for(int l = 0; l<langTable[r.language].Count; l++){
				fileWriter.WriteLine(wtts[l]+"");
				fileWriter.WriteLine(langTable[r.language][l].ToString());
			}
			
			fileWriter.Close();
			
		}	
	
	}

Thanks for taking the time to post this. I understand however that the LitJson doesn’t work on an iPhone so I believe I can’t use that?

Did you give up on JsonFX (I’m close to doing so…)