两个json,结构不一样,值是一样的,怎么对比让他们相等?

bzzzzzzzzz 2015-06-02 05:09:08
public static void main(String[] args) {

String str = "{\"name\":\"Michael\",\"address\":{\"city\":\"Beijing\",\"street\":\" Chaoyang Road \",\"postcode\":100025}}";
String strTwo = "{\"address\":{\"city\":\"Beijing\",\"street\":\" Chaoyang Road \",\"postcode\":100025},\"name\":\"Michael\"}";
System.out.println(compareJson(str,strTwo));
}
str 和 StrTwo应该是相同的

compareJson(str1,str2);
方法如何写?
...全文
613 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
衣舞晨风 2015-06-02
  • 打赏
  • 举报
回复
刘欣的博客 2015-06-02
  • 打赏
  • 举报
回复


using Newtonsoft.Json;
using Newtonsoft.Json.Converters;


    public class farm
    {
        public int id { get; set; }
        public string utime { get; set; }
        public string playername { get; set; }
        public string farmname { get; set; }
        public int zlevel { get; set; }
        public int blood { get; set; }
        public int x { get; set; }
        public int y { get; set; }
        public int rice { get; set; }
        public int stat { get; set; }
        public int speed { get; set; }
        public int step { get; set; }
        public string pic { get; set; }
        public int maxstorage { get; set; }
        public int workstep { get; set; }
        public int riceoutput { get; set; }
        public string zmessage { get; set; }
    }


 List<farm> tmplist = JsonConvert.DeserializeObject<List<farm>>(s);


  • 打赏
  • 举报
回复
showjim 2015-06-02
  • 打赏
  • 举报
回复
试试fastCSharp
        struct x
        {
            public string name;
            public y address;
        }
        struct y
        {
            public string city;
            public string street;
            public int postcode;
        }
            string str = "{\"name\":\"Michael\",\"address\":{\"city\":\"Beijing\",\"street\":\" Chaoyang Road \",\"postcode\":100025}}";
            string strTwo = "{\"address\":{\"city\":\"Beijing\",\"street\":\" Chaoyang Road \",\"postcode\":100025},\"name\":\"Michael\"}";
            Console.WriteLine(fastCSharp.emit.equals<x>.Equals(fastCSharp.emit.jsonParser.Parse<x>(str), fastCSharp.emit.jsonParser.Parse<x>(strTwo)));
Imcx 2015-06-02
  • 打赏
  • 举报
回复
的字段值
Imcx 2015-06-02
  • 打赏
  • 举报
回复
对象取出来放数组里,再进行对比 参考
xuzuning 2015-06-02
  • 打赏
  • 举报
回复
转成队形再比较
bdmh 2015-06-02
  • 打赏
  • 举报
回复
转成对象,然后比较里面的字段值

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧