Parsing your JSON didn't work. Please make sure it's valid

Parsing your JSON didn't work. Please make sure it's valid

I need help with parsing a JSON output.

My app returns the webrespose in following format

"[4,\"1.0\",1376832093410]\r\n[1,\"Jack Dev\",\"177\",1376832181000]\r\n[1,\"Jason Make\",\"53\",1376832711000]\r\n[1,\"Dev Mark\",\"177\",1376832747000]\r\n

When I try to same from browser I get the following output in a .JSON file.

[4,"1.0",1376831235858]
[1,"Jack Dev","177",1376831512000]
[1,"Jason Make","53",1376831610000]
[1,"Dev Mark","53",1376831931000]

I am trying to parse this file. I used http:-//json2csharp.-com/ and pasted this and got the following error

Parsing your JSON didn't work. Please make sure it's valid.
Already did that? Please let me know so I can fix it.

I looks a lot of tutorials online but dint get anything. Can someone help me with some tutorials as to how to handle this ?

As its Not Proper JSON Format. You Cannot Parse As We Normally Do With JSON by Identify Its Key Value Like This.

{
    "Brand": "Nokia","Type" : "Lumia 800",
    "Specs":{"Storage" : "16GB", "Memory": "512MB","Screensize" : "3.7"}
  }


As you can see above Is Proper JSON Format and you Can Extract Values By Doing JSON Parsing On Attribute Like Brand, Type, Spec, Memory And ScreenSize

In Your Case You Are Getting Like This And Fix Number Of Attributes For All Records


[1,"Jack Dev","177",1376831512000],
[1,"Jason Make","53",1376831610000],
[1,"Dev Mark","53",1376831931000]

Not Like This There Is Variation in Number Of Attributes

[1,"Jack Dev",1376831512000],
[1,"Jason Make","53",1376831610000],
[Dev Mark","53",1376831931000]

If You Are Getting Fixed Number Of Attributes Then You Can Get Values Of Attributes In This Way For Non JSON Format

 

 void DoTheTrick()       
{          
string Response = @"                         
[1,'Jack Dev','177',1376831512000]                        
,[1,'Jason Make','53',1376831610000]                        
,[1,'Dev Mark','53',1376831931000]".Trim();           
// Splited For [] So We Can Total Number Of Records         
string[] Splited = Response.Split(new string[] { ",[" }, StringSplitOptions.None);         
List<Arslan> List = new List<Arslan>();         
for (int i = 0; i <= Splited.Length - 1; i++)         
{             
// Spiting Again And Removing For Start "[" And End "]" And SPliting On "," To Get All Attributes            
string[] SpiltedAgain =  Splited[i].Replace("[", "").Replace("]","").Split(',');             
//Adding This New List             
List.Add(new Arslan { Item1 = SpiltedAgain[0], Item2 = SpiltedAgain[1], Item3 = SpiltedAgain[2], Item4 = SpiltedAgain[3] });         
}      
}      
 public class Arslan       
{           
public string Item1 { get; set; }           
public string Item2 { get; set; }           
public string Item3 { get; set; }           
public string Item4 { get; set; }       

  • Back aarticle:
  • Next aarticle: No
  • Copyright © 2007-2012 www.chuibin.com Chuibin Copyright