Saturday 1 July 2017

Json Parsing in unity c#

hey guys, here is the script of JsonParsing in unity with c#, make sure you have to add SimpleJSON.cs and ICSharpCode.SharpZipLib.dll in your plugin folder.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SimpleJSON;

public class SearchFriends : Monobehavior {

public string[] F_ID;
private string GetdataApi="http://yourApiLink";

void GetAllId()
{
JSONNode jsonNode = SimpleJSON.JSONNode.Parse (GetdataApi);
int a = jsonNode.Count;
F_ID = new string[a];
for (int i = 0; i < a; i++)
{
F_ID [i] = jsonNode [i] ["id"].ToString (); // change ["id"] with your DB parameter.
F_ID [i] = F_ID [i].Replace ("\"", "");
}
}

by this you can find all the id from the database. make sure you have to change ["id"] with your database parameter name.

by the similar way you can find all the field of database like "username" , "email", "gender" etc. just you have to change ["id"] by this name.


... Be Happy....:) :)

No comments:

Post a Comment