After requesting the project inventory from Xerial services, the JSON response needs to be processed to create an instance of the UserData class.
Usage
using System.Collections.Generic;
using UnityEngine;
using SimpleJSON;
using Xerial;
public class NFTResponseHandler
{
public void HandleNFTResponse(string response)
{
XerialServices.instance.inventoryManager.inventory = null;
JSONArray jsonArray = JSON.Parse(response).AsArray;
if (jsonArray != null && jsonArray.Count > 0)
{
JSONNode rootNode = jsonArray[0];
//Deserialize the object array
}
}
Deserializing NFTs from Project Inventory Data
To deserialize the NFTs from the JSON response within the project inventory data.
NFT
First, we retrieve the node containing NFT data from the JSON response received from the server. c
NFT nft = new NFT();
int quantity = rootNode["quantity"].AsInt;
nft.amount = quantity;
JSONNode collectionNode = rootNode["collection"];
nft.collection = new Collection();
JSONNode metadataNode = rootNode["metadata"];
nft.metadata = new Metadata();
JSONArray tokensArray = rootNode["tokenIds"].AsArray;
nft.tokens = new List<Token>();
Collection
nft.collection = new Collection();
nft.collection.Id = collectionNode["id"].Value;
nft.collection.TxHash = collectionNode["txHash"].Value;
Metadata
nft.metadata = new Metadata();
nft.metadata.name = metadataNode["name"].Value;
nft.metadata.description = metadataNode["description"].Value;
nft.metadata.image = metadataNode["image"].Value;
nft.metadata.externalUrl = metadataNode["externalUrl"].Value;
JSONNode contractnode = rootNode["metadata"]["contract"];
nft.metadata.contract = new Contract();
nft.metadata.attributes = new List<Attributes>();
foreach (JSONNode attributeNode in metadataNode["attributes"].AsArray)
{
Attributes attribute = new Attributes();
nft.metadata.attributes.Add(attribute);
}