I have a json file like this:

{
    "list": [
        {
            "ID" : "1",
            "value" : "value is one"
        }
        {
            "ID" : "2",
            "value" : "value is two"
        }
        {
            "ID" : "3",
            "value" : "value is three"
        }
        {
            "ID" : "4",
            "value" : "value is four"
        }
    ]
}


what I want to do is read the josn file and returns the message based on the ID i specify. So for example

if (this.list.containsKey("1"))
    {
        return this.list.get(messageTitle);
    }


That's what I tried but it returns all the values and ID.

JSONParser parser = new JSONParser();
try {
    Object obj = parser.parse(new FileReader("jsonFile.json"));
    JSONObject jsonObject = (JSONObject) obj;
    // loop array
    JSONArray msg = (JSONArray) jsonObject.get("list");
    Iterator&lt;String&gt; iterator = msg.iterator();
    while (iterator.hasNext()) {
        System.out.println(iterator.next());
    }
}



Question: create a list (or any variable) dynamically, add data to each list and later compare them in C#
Answer: You can use IList&lt;KeyValuePair&lt;String,IList&lt;SomethingData&gt;&gt;&gt; or Hastable&lt;String,IList&lt;SomethingData&gt;&gt;

 //fill data to lists
 IList&lt;KeyValuePair&lt;String,IList&lt;SomethingData&gt;&gt;&gt; dataSets=new  List&lt;KeyValuePair&lt;String,IList&lt;SomethingData&gt;&gt;&gt;();
 IList&lt;string&gt; names = new List&lt;String&gt;();
 foreach (string nm in names)
 {
     IList&lt;SomethingData&gt; data = new List&lt;SomethingData&gt;();
     //...fill data
     dataSets.Add(new KeyValuePair&lt;string, IList&lt;SomethingData&gt;&gt;(nm, data));
 } 

 //search lists by name
 String nameForSearch = "test";
 IEnumerable&lt;KeyValuePair&lt;String,IList&lt;SomethingData&gt;&gt;&gt; dataSetsByName = dataSets.Where(ds =&gt; ds.Key == nameForSearch);