c#(csharp .net)下使用json

c#(csharp .net)下使用json


http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html
下载json.cs

使用如下:
string  jsonText  =   " [{\ " name\ " :\ " 123 \ " ,\ " name2\ " :[{\ " ip\ " :-456e8}]},{\ " name\ " :\ " 123 \ " ,\ " name2\ " :[{\ " ip\ " :-456e1}]}] " ;

            ArrayList listInfo 
=  (ArrayList)JSON.JsonDecode(jsonText);
            ArrayList listTo 
=   new  ArrayList();
            
for ( int  i  =   0 ; i  <  listInfo.Count; i ++ )
            
{
                Hashtable hInfo 
= (Hashtable)listInfo[i];
                listTo.Add(hInfo);

                
string name = (string)hInfo["name"];
                ArrayList aname2 
= (ArrayList)hInfo["name2"];
                Hashtable hname2ip 
= (Hashtable)aname2[0];
                
double ip1 = (double)hname2ip["ip"];
            }


            
string  toJson  =   "" ;
            toJson 
=  JSON.JsonEncode(listTo);
            Console.WriteLine(toJson);


更多使用可以参考
http://www.json.org/ 的使用。

你可能感兴趣的:(c#(csharp .net)下使用json)