0

I have a complex object as follow

public class Cart
{
  public int cartID{get; set;}
  public bool IsActive{get; set;}
  public double price{get; set;}
  public List<Items> items{get; set;}
}

public class Item
{
  public int itemID{get; set;}}
  public string itemName{get;set;}
  public double price{get; set;}
}

My service accepts a json as follows

public class ServiceRequest
{
 public string Data{get;set;}
 public string ActionToBePerformed{get;set;}
}

where ActionToBePerformed- indicate which operation to perform.
          Data- is the serialized list of object Cart

How to serialize the Cart object into string in windows phone 7 and send it to the service as Data of object ServiceRequest?(without using any third party JSON library as JSON.net)

gjdev.tech
  • 135
  • 2
  • 11

1 Answers1

0

(without using any third party JSON library as JSON.net)

Then you should write your own serializer - but this is just inventing a wheel again.

You know that JSON structure is:

Array: [], etc.

If you need to serialize 2 objects - action and dta then its an array with 2 objects:

[{
    "Data":
    {
    "*Name of your cartID on the service*": cartID, (value from C# class)
    "*Name of your IsActive on the service*": IsActive, (value from C# class)
    "*Name of your price on the service*": price, (value from C# class)
    "*Name of your List<Items> on the service*":
    [{
        List<Items>
    }]
    }
    "ActionToBePerformed": Here if it is just a string
    {
         Here if it is a class like data
    }
}]

So if you know what JSON should look like, than you can write this using a few FOR's

Just find needed CART in your List or whatever and write:

string JSON="[{"Data":"Name of your cartID on the service": + " cartID, (value from C# class) and so on...

How i said its inventing a wheel...

Developer
  • 4,158
  • 5
  • 34
  • 66