Creating UserData Class

After requesting user data from Xerial services, the JSON response needs to be processed to create an instance of the UserData class.

using System.Collections.Generic;
using Xerial;

public class DeserializeUserData
{
  public UserData ProcessJsonResponse(string jsonResponse)
  {
      // Method implementation
  }
}

Deserializing Account Data

To deserialize the account data from the JSON response, we first retrieve the relevant node from the JSON data and then create an instance of the Account class. Here's how it's done:

Explanation

We extract the "user" object from the JSON data and create a new instance of the Account class. We then assign the values of the "identifier" and "id" properties to the corresponding properties of the Account instance.

Example

// Process the "user" object
JSONNode userNode = jsonNode["user"];
Account user = new Account
{
    identifier = userNode["identifier"],
    id = userNode["id"]
};

Deserializing Wallet Data

To deserialize the wallet data from the JSON response, we iterate through the "wallets" array, create Wallet instances for each object, and collect them in a list. Here's how it's done:

Explanation

We iterate through the "wallets" array in the JSON data. For each object in the array, we create a new Wallet instance and assign its properties by extracting values from the corresponding JSON properties. We then add each Wallet instance to a list.

Example

List<Wallet> walletList = new List<Wallet>();

// Process the "wallets" array
JSONArray walletsArray = jsonNode["wallets"].AsArray;
if (walletsArray != null)
{
    foreach (JSONNode walletNode in walletsArray)
    {
        Wallet wallet = new Wallet
        {
            user = walletNode["user"],
            address = walletNode["address"],         
            smartAccount = walletNode["smartAccount"],
            custodial = walletNode["custodial"].AsBool,
            id = walletNode["id"]
        };
        walletList.Add(wallet);
    }
}

Last updated