How to read json using unity and using JSONObject

reminder : unity now(3.5.15) support .net framework 3.5 max.

1)download from the Asset Store the JSON Object 1.5.1 (it’s free)

2)create new c# script that will be our Serializer, For my need i build only one fuction that DeSerialize into Dictionary.

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

public static class Serializer{
	private static Dictionary dictionaryFromJsonStrStr = new Dictionary ();

	public static Dictionary DeSerialize(string Json1)
		JSONObject jsonCharInfo = new JSONObject (Json1);
		int numOfListsInJson = jsonCharInfo.list.Count;
		for (int k=0; k<numOfListsInJson; k  ) {
			for (int i=0; i<jsonCharInfo.list[k].keys.Count; i  ) {
				string key = (string)jsonCharInfo.list[k].keys [i];
				JSONObject value = (JSONObject)jsonCharInfo.list[k].list [i];
					dictionaryFromJsonStrStr [key] = value.str;
		return dictionaryFromJsonStrStr;

in the bitbucket i put the project files and also extention of the Serializer so i can do more than DeSerialize.

3)put json file on your server that look like this

   "mobileApps": {
     "samsung" : "good",
     "nokia" : "nice",
     "lg" : "bad",
	 "asaf" : "at your service"
   "downloadApp" : {
    "froge" : "angry",
     "chiken" : "smile",
     "samsung" : "lovly",
	 "nice" : "bla"

in the unity project put the link to json file.

4)open the project in unity and run it

This entry was posted in כללי and tagged , , . Bookmark the permalink.

4 Responses to How to read json using unity and using JSONObject

  1. Could you fix the bitbucket link? I can’t access your repository.


  2. asafshay says:

    the link is ok, the thing it’s private, but you don’t need that, the code in the post should be enough for you.


  3. emre boyraz says:

    i would like to look at the project could you please make link public?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s