0

次のような複雑なオブジェクトがあります

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;}
}

私のサービスは次のようにjsonを受け入れます

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

ActionToBePerformed - 実行する操作を示します。
          Data- はオブジェクト Cart のシリアル化されたリストです

Windows Phone 7 で Cart オブジェクトを文字列にシリアル化し、それをオブジェクト ServiceRequest のデータとしてサービスに送信する方法は? (サードパーティの JSON ライブラリを JSON.net として使用せずに)

4

1 に答える 1

0

(サードパーティの JSON ライブラリを JSON.net として使用せずに)

次に、独自のシリアライザーを作成する必要がありますが、これは車輪の再発明にすぎません。

JSON 構造は次のとおりです。

配列: [] など

action と dta の 2 つのオブジェクトをシリアル化する必要がある場合は、2 つのオブジェクトを含む配列になります。

[{
    "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
    }
}]

したがって、JSON がどのように表示されるかがわかっている場合は、いくつかの FOR を使用してこれを記述できます。

リストなどで必要なカートを見つけて、次のように記述します。

string JSON="[{"Data":"サービスのカート ID の名前": + " カート ID、(C# クラスの値) など...

車輪の発明とはなんと言った...

于 2013-10-01T06:30:35.460 に答える