对JSON格式化

//处理JSON数据格式
  public string json(string json)
  {
   string []index1=Getindex(json,"\'").Split(',');
   string []index2=Getindex(json,"\\“).split(',');
   for(int i=0;i<index1.Length-1;i++)
   {
    json.Insert(int.Parse(index1[i]), "\\");
   }
   for(int j=0;j<index2.Length-1;j++)
   {
    json.Insert(int.Parse(index2[j]), "\\");
   } 
   return json.Replace("\r", "\\r").Replace("\n", "\\r");
  }

  public string Getindex(string a,string b)
  {
   string cccc="";
   int i=0;
   int index=a.IndexOf(b);
   while(index>=0)
   {
    cccc+=index+",";
    i++;
    index=a.IndexOf(b,index+1,a.Length-1-index);
   }
   return cccc;
  }

posted @ 2009-07-17 14:38  悟〈--觉  阅读(460)  评论(1编辑  收藏  举报