-3

I want to create and write jsonarray like in this link http://api.learn2crack.com/android/jsonos/. I researched but I could not find example that satisfy me.

I know how I write as JsonString, for example:

string jsonstring = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(obj);

But I have a array in asp.net and I want to write that array as JSONarray like this

{ "android": 
        [ 
          { "ver": "1.5", "name": "Cupcake", "api": "API level 3" }, 
          { "ver": "1.6", "name": "Donut", "api": "API level 4" }
        ]
} 
3
  • For what purpose? If you're returning JSON to the client in response to a request then it's just a string. You can build and return the JSON directly as a string. Alternatively, you can use something like the JavaScriptSerializer to serialize an object into JSON. Or, if you're using MVC, you can return a Json() result. Or, with WebAPI, just return the object being serialized. There are lots of ways to do this. Where are you stuck? Commented Apr 7, 2014 at 17:05
  • I know how I write as JsonString ex: ...string jsonstring = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(obj);... but I have a array in asp.net and I want to write that array as JSONarray like this { "android": [ { "ver": "1.5", "name": "Cupcake", "api": "API level 3" }, { "ver": "1.6", "name": "Donut", "api": "API level 4" }]} Commented Apr 7, 2014 at 17:15
  • possible duplicate of Serialize to JSON in .NET 2.0 Commented Apr 7, 2014 at 17:34

1 Answer 1

0

Why do I have a feeling that the OP isn't a type safe developer and is actually asking, "how do I write a class that serializes to 'this' output?"

public class Foo
{
    public List<Bar> Android {get;set;}

}
public class Bar
{
    public string Ver { get; set; }
    public string Name { get; set; }
    public string Api { get; set; }
}

var foo = new Foo{
     Android = new List<Bar>
     {
         new Bar { Ver = "1.5", Name = "Cupcake", Api = "Api Level 3"},
         new Bar { Ver = "1.6", Name = "Donut", Api = "Api Level 4"},
     }
};
var bar = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(foo);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.