Is it possible to run a foreach loop on JSONObject with key value pairs?

Can we run a foreach loop on JSONObject in Unity3D such that key value pairs can both be extracted?

What “JSONObject” do you refer to? Do you mean [this one on the wiki][1]? If so you can use a for loop like this:

JSONObject o;

for(int i = 0; i < o.list.Count; i++)
{
    string key = o.keys*;*

JSONObject val = o.list*;*
}
foreach can’t be used with that framework as they don’t store the items as key value pairs but in two seperate lists. With my [SimpleJSON][2] it’s possible.
_[1]: http://wiki.unity3d.com/index.php?title=JSONObject*_
_
[2]: http://wiki.unity3d.com/index.php/SimpleJSON*_

Unity has a build in tool for Json file (Unity - Scripting API: JsonUtility), it converts Json to c# class. So you can use it in oder to work with c# class (or struct) representation of Json. There you can use for, foreach and so on…

I recommend to make json from array and store it when you like to loop through the array simply create array from the json file.