Click here to Skip to main content
15,895,192 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
 catch (Exception ex)
            {
			 throw ex;
				
            }
            finally
            {
                con.Close();
            }


            ArrayList a = new ArrayList();
            a.Add(reportList);
            a.Add(p);
 if (reportList.Count()  != 0)
            {
 return JsonConvert.SerializeObject(a);
            }
			else{
			
			return // "custom message records not found"
}


What I have tried:

 catch (Exception ex)
            {
			 throw ex;
				
            }
            finally
            {
                con.Close();
            }


            ArrayList a = new ArrayList();
            a.Add(reportList);
            a.Add(p);
 if (reportList.Count()  != 0)
            {
 return JsonConvert.SerializeObject(a);
            }
			else{
			
			return // "custom message records not found"
}
Posted
Updated 26-Jul-17 18:43pm

You can create object and then convert it to json object. Example.

public class ValidationMessage
{
    public int success { get; set; }
    public string message { get; set; }
}
Usage:

var valMessage = "{\"success\":1,\"message\":\"successfully created.\"}";
return JsonConvert.DeserializeObject<ValidationMessage>(valMessage);
 
Share this answer
 
Comments
[no name] 29-Jul-17 0:53am    
Thank you sir.
try this
just compare the first index value of the json array in javascript

if (reportList.Count()  != 0)
            {
            a.Add("success");
              a.Add(reportList);
            a.Add(p); 
            }
			else {
            a.Add("failure");
              a.Add("Your custom message");  
        }
             return JsonConvert.SerializeObject(a);
 
Share this answer
 
v2
Comments
[no name] 29-Jul-17 0:53am    
Thank you sir.
Karthik_Mahalingam 31-Jul-17 0:45am    
welcome
[no name] 2-Aug-17 1:19am    
sir would you please check at this issue :
https://www.codeproject.com/Questions/1199385/How-do-I-send-list-of-object-back-to-server
Karthik_Mahalingam 2-Aug-17 1:32am    
looks like it is solved

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900