Amit Sharma
Amit Sharma

Reputation: 1088

how to convert JSON array to string ..?

I want to return string values from a web method function, presently it returning JSON array value as:

{"statusCode":200,"result":{"totalCount":1,"resultCount":1,"items":[{"Category":"Content Types","Database":"master","DisplayName":"New Home","HasChildren":false,"Icon":"/temp/IconCache/Network/16x16/home.png","ID":"{7FA85E0C-5E09-4B8E-9F1C-B362D562FADD}","Language":"en","LongID":"/{11111111-1111-1111-1111-111111111111}/{0DE95AE4-41AB-4D01-9EB0-67441B7C2450}/{8418FEEC-DC96-42C5-AC38-AD3942497A18}/{7FA85E0C-5E09-4B8E-9F1C-B362D562FADD}","MediaUrl":"/~/icon/Network/48x48/home.png.aspx","Name":"New Home","Path":"/sitecore/content/Content Types/New Home","Template":"User Defined/test /Content Types/Home","TemplateId":"{8112E624-DAD0-429C-A185-BE4A82A2D648}","TemplateName":"Home","Url":"~/link.aspx?_id=7FA85E0C5E094B8E9F1CB362D562FADD\u0026amp;_z=z","Version":1,"Fields":{}}]}} 

i'm trying something like this to convert it to string :

System.Web.Script.Serialization.JavaScriptSerializer js = new     System.Web.Script.Serialization.JavaScriptSerializer();
        var table = js.DeserializeObject<string>(jsonArray);

can some one help me how to make it happen.

Upvotes: 1

Views: 128

Answers (1)

rishiraj shekhawat
rishiraj shekhawat

Reputation: 194

you can try like this:

      var strOuptut = readStream.ReadToEnd();
       Newtonsoft.Json.Linq.JObject obj = Newtonsoft.Json.Linq.JObject.Parse(strOuptut);
       StringBuilder html = new StringBuilder();

Upvotes: 2

Related Questions