Advertisement
MelonLupi

comparembolah3

Mar 27th, 2017
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using LitJson;
  5. using System;
  6.  
  7. public class coba3 : MonoBehaviour {
  8.  
  9.     // Use this for initialization
  10.     void Start () {
  11.         string json = @"
  12.            {
  13.                ""Age1"" : 10,
  14.                ""Age2"" : 20,
  15.                ""Age3"" : 30
  16.            }";
  17.  
  18.         string json1 = @"
  19.            {
  20.                ""Age1"" : 60,
  21.                ""Age2"" : 50,
  22.                ""Age3"" : -100
  23.            }";
  24.  
  25.         JsonData thomasdata = JsonMapper.ToObject (json);
  26.         JsonData mattdata = JsonMapper.ToObject (json1);
  27.         Debug.Log(comparison (mattdata, thomasdata,10,2));
  28.     }
  29.  
  30.     public class Person
  31.     {
  32.         // C# 3.0 auto-implemented properties
  33.         public string   Name     { get; set; }
  34.         public int      Age      { get; set; }
  35.     }
  36.        
  37.     public bool comparison(JsonData input, JsonData target, int threshold, int maxerror)
  38.     {
  39.         string[] kunci = new string[target.Count];
  40.         int x = 0, y = 0, z = 0;
  41.         int jumsalah = 0;
  42.         int[] beda = new int[target.Count];
  43.         foreach (string key in target.Keys) {
  44.             kunci [x] = key;
  45.             x++;
  46.         }
  47.  
  48.         for (x = 0; x < target.Count; x++) {
  49.             y = (int)input [kunci [x]];
  50.             z = (int)target [kunci [x]];
  51.             beda [x] = Math.Abs(y - z);
  52.             if (beda [x] > threshold)
  53.             {
  54.                 jumsalah++;
  55.             }
  56.         }
  57.  
  58.         if (jumsalah < maxerror) {
  59.             return true;
  60.         }
  61.         return false;
  62.  
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement