MetaData.cs 1.68 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MoyaAdminLib
{
    public class MetaData
    {
        public string key;
        public string value;

        public static MetaData GetValue(string ret)
        {
            MetaData data = null;

            if (ret != null && ret != "")
            {
                ret = ret.Trim();
                if (ret.StartsWith("{") && ret.EndsWith("}"))
                {
                    ret = ret.Replace("{", "");
                    ret = ret.Replace("}", "");
                    if (ret.Contains(":"))
                    {
                        data = new MetaData();
                        string[] fields = ret.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                        if (fields.Length == 2)
                        {
                            if (fields[0].StartsWith("\""))
                                fields[0] = fields[0].Substring(1, fields[0].Length - 1);
                            if (fields[0].EndsWith("\""))
                                fields[0] = fields[0].Substring(0, fields[0].Length - 1);
                            data.key = fields[0];
                            if (fields[1].StartsWith("\""))
                                fields[1] = fields[1].Substring(1, fields[1].Length - 1);
                            if (fields[1].EndsWith("\""))
                                fields[1] = fields[1].Substring(0, fields[1].Length - 1);
                            data.value = fields[1];
                        }
                    }
                }
            }

            return data;
        }
    }
}