using LitJson;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Jsonanalyze : MonoBehaviour
{
///
/// 通过网络字符串转换成对象
///
///
///
///
public static T FromJson(string str)
{
if (str != null && !string.IsNullOrEmpty(str))
{
str = str.Replace("\\\"", "\"");
// str = str.Replace("\\n", "\n");
// str = str.Replace(" ", "");
// str = str.Replace("\t", "");
if (str.Length > 2)
{
if (str[0] == '"')
{
str = str.Substring(1, str.Length - 1);
str = str.Substring(0, str.Length - 1);
}
// Debug.Log("FromJson字符串:"+ str);
return JsonMapper.ToObject(str);
}
else
{
Debug.LogError("字符串长度不够!");
}
}
else
{
Debug.LogError("字符串错误!");
}
return default(T);
}
public static string JsonData(string str)
{
if (str != null && !string.IsNullOrEmpty(str))
{
str = str.Replace("\\\"", "\"");
if (str.Length > 2)
{
if (str[0] == '"')
{
str = str.Substring(1, str.Length - 1);
str = str.Substring(0, str.Length - 1);
}
}
else
{
Debug.LogError("字符串长度不够!");
}
}
else
{
Debug.LogError("字符串错误!");
}
return str;
}
}