Beispiel #1
0
        static void LoadJSONClass(JSONObject JSONObj,object parsed_json)
        {
            if (parsed_json is Hashtable)
            {
                Hashtable parsed_json_ht = (Hashtable)parsed_json;
                foreach (DictionaryEntry de in parsed_json_ht)
                {
                    Console.Write("k:" + de.Key);

                    if(de.Value is Hashtable || de.Value is ArrayList)
                    {
                        Console.WriteLine(" ");
                        LoadJSONClass(JSONObj, de.Value);
                    }
                    else
                    {
                        Console.WriteLine(" v:" + de.Value.ToString());
                    }
                }
            }
            else if (parsed_json is ArrayList)
            {
                ArrayList parsed_json_al = (ArrayList)parsed_json;
                foreach( object obj in parsed_json_al)
                {
                    Console.WriteLine(obj.ToString());
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            string exampleJSON = "{ \"soda\" : \n"
                                + "  { \"device\": \n"
                                + "    { \"mfg\": \"Vandelay Industries\", \n"
                                + "      \"model\": \"Red Dot\", \n"
                                + "      \"firmware\": \"1.1.2\", \n"
                                + "      \"hardware\": \"1.0.0\", \n"
                                + "      \"serial-number\": \"L97364892383\", \n"
                                + "      \"soda-class\": [ \"wwan\", \"hotspot\", \"gps\" ] \n"
                                + "    } \n"
                                + "  } \n"
                                + "}\n";


            Console.WriteLine(exampleJSON);
            bool success = false;
            object result = JSON.JsonDecode(exampleJSON, ref success);

            JSONObject rootObj = new JSONObject();

            LoadJSONClass(rootObj, result);
            
            rootObj = new JSONObject();
        }