I have a string which is \"primaryKey\":0,\"kills\":0,\"death\":0,\"isconnected\":1,\"isbanned\":0,\"issurrend\":0
I need to format it to
"kills":3,
"death":0,
"isconnected":1,
"isbanned":0,
"issurrend":0,
"userId":4,
Any1 knows how to do this.
Thanks
You could fairly easily use string.Replace(“,”, “\n”) to accomplish what you’re trying to do.
…but this feels like a problem that could be solved more correctly if we had a little bit more context as to what you’re trying to do. This looks a lot like json, but I can’t imagine a scenario in which you’d need to convert all-in-one line json to newline’d json, especially since every JSON reader class on the planet can handle both (and, if you did need one in particular, most can export both).
So I guess the question is, where is that first string coming from and what is it you need to accomplish with it?
Heres my full code
OtherInfo other = new OtherInfo();
Debug.Log ("endgame started");
foreach (PhotonPlayer ply in PhotonNetwork.playerList)
{
PlayerInfo playerInfo = new PlayerInfo();
playerInfo.primaryKey = PlayerPrefs.GetInt("primaryKey");
playerInfo.kills = ply.GetKills();
playerInfo.death = ply.GetDeaths();
playerInfo.isconnected = 1;
playerInfo.isbanned = 0;
playerInfo.issurrend = 0;
other.players.Add(JsonUtility.ToJson(playerInfo));
index++;
}
StartCoroutine(PostMatch(JsonUtility.ToJson(other)));
IEnumerator PostMatch(string str)
{
WWWForm form = new WWWForm();
form.AddField("jsonData", str);
WWW w = new WWW("http://xxxxxxx/post.php", form);
yield return w;
Debug.Log ("post match called");
Debug.Log(str);
}
when i use Debug.Log(str);
its in 1st format while i want it to be like in 2nd format of my above post