1

How can I convert php array to c# string(xml or json)?

  [ID] => 1
  [CreditNo] => 2
  [Date] => 2017-06-15

I have found some source but they dont work

Programmer
  • 29
  • 7
  • Show us what you've tried and how it failed – Bassie Apr 14 '17 at 13:59
  • 4
    Possible duplicate of [Converting PHP result array to JSON](http://stackoverflow.com/questions/2122233/converting-php-result-array-to-json) – LF00 Apr 14 '17 at 14:02
  • 1
    @KrisRoofe to my mind it is not duplicate of http://stackoverflow.com/questions/2122233/converting-php-result-array-to-json – Programmer Apr 14 '17 at 14:06
  • 1
    @Bassie I have used https://www.codeproject.com/script/articles/articleversion.aspx?aid=292712&av=433386 link but i get error – Programmer Apr 14 '17 at 14:08
  • It looks like the link @KrisRoofe provided explains well how to convert a php array to JSON. I tried it on http://phpfiddle.org/ and it seems to work. If that's not what you're wanting you may need to rephrase the question. – KSib Apr 14 '17 at 15:07
  • 1
    I want to do it with c# codes – Programmer Apr 15 '17 at 05:10
  • @Sake Do you have an example input which produces the error? – Bassie Apr 15 '17 at 14:18

1 Answers1

1

Convert the json to xdocument and get the results

var xml = XDocument.Load(JsonReaderWriterFactory.CreateJsonReader(
    Encoding.ASCII.GetBytes(JsonString), new XmlDictionaryReaderQuotas()));

var resultlist=xml.Descendants("item"); // to get the direct node value result as list
Max Gaurav
  • 1,835
  • 2
  • 13
  • 26