Click here to Skip to main content
15,895,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to conert json string to json array
.My json string
[{"MASON_ID":"17768","UPLOAD_DATE":"2016-07-21 11:38:16","NAME":"SURESH","MOBILE_NO":"9720810615","EMP_NAME":"Maneesh Kumar"},
{"MASON_ID":"17791","UPLOAD_DATE":"2016-07-26 10:31:07","NAME":"Saurav parashar","MOBILE_NO":"8909445300","EMP_NAME":"Maneesh Kumar"},
{"MASON_ID":"17848","UPLOAD_DATE":"2016-07-28 10:26:15","NAME":"BIJENDRA SINGH","MOBILE_NO":"9927338220","EMP_NAME":"Maneesh Kumar"},
{"MASON_ID":"18868","UPLOAD_DATE":"2016-09-05 09:03:30","NAME":"INDRAPAL","MOBILE_NO":"8859859956","EMP_NAME":"Maneesh Kumar"},
{"MASON_ID":"19396","UPLOAD_DATE":"2016-09-05 09:07:47","NAME":"JITENDRA KUMAR","MOBILE_NO":"9536304935","EMP_NAME":"Maneesh Kumar"},
{"MASON_ID":"19652","UPLOAD_DATE":"2016-09-03 11:48:29","NAME":"ASAHAR JAMA","MOBILE_NO":"9760390094","EMP_NAME":"Maneesh Kumar"},
{"MASON_ID":"19653","UPLOAD_DATE":"2016-09-03 11:52:19","NAME":"BABUJI","MOBILE_NO":"9568398567","EMP_NAME":"Maneesh Kumar"},
{"MASON_ID":"19678","UPLOAD_DATE":"2016-09-05 09:16:12","NAME":"HARISH","MOBILE_NO":"9152675257","EMP_NAME":"Maneesh Kumar"}]

What I have tried:

C#
//JavaScriptSerializer js = new JavaScriptSerializer();
                   //string json = js.Serialize(obj);
                   //  JObject json = JObject.Parse(data);
                   string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(data);
Posted
Updated 29-Mar-18 17:17pm
Comments
Karthik_Mahalingam 18-Oct-16 3:58am    
what is the issue ?
Suvendu Shekhar Giri 18-Oct-16 5:07am    
Try -
JObject.Parse()
JObject.Parse Method (String)[^]
F-ES Sitecore 18-Oct-16 5:46am    
To go from a string to the data\object you need to deserialize, so google "c# deserialize json string" for examples. You're using the write objects, just the wrong methods.

C#
Here you get JSONObject so change

JSONArray jsonArray = new JSONArray(readlocationFeed); 
line with following

JSONObject jsnobject = new JSONObject(readlocationFeed);
and after

 JSONArray jsonArray = jsnobject.getJSONArray("locations");
    for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject explrObject = jsonArray.getJSONObject(i);
}
 
Share this answer
 
Since you are using newtonsoft, you can do this.

C#
string yourText = "";
JArray textArray = JArray.Parse(yourText);

This will return an array of of your object.
 
Share this answer
 
Comments
Patrice T 30-Mar-18 2:18am    
18 months too late.

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