JsonArrayToStringConverter.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using Newtonsoft.Json.Linq;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Data;
  9. namespace MedicallCenter.Clasees
  10. {
  11. internal class JsonArrayToStringConverter : IValueConverter
  12. {
  13. public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
  14. {
  15. if (value == null) return string.Empty;
  16. JArray jsonArray = JArray.Parse(value.ToString());
  17. string str = "";
  18. List<Service> cur_services = new List<Service>();
  19. int i = 0;
  20. foreach (JObject jobj in jsonArray)
  21. {
  22. str+= CurrentData.services.FirstOrDefault(n => n.kod_service == (int)jobj["code"]).service1;
  23. if(i+1<jsonArray.Count)
  24. str += ", ";
  25. i++;
  26. }
  27. return str;
  28. }
  29. public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture)
  30. {
  31. throw new NotImplementedException();
  32. }
  33. }
  34. }