Click here to Skip to main content
15,903,012 members
Home / Discussions / C#
   

C#

 
GeneralRe: Detect Network / VPN Connection Part 2 Pin
Kevin Marois15-Nov-18 10:42
professionalKevin Marois15-Nov-18 10:42 
GeneralRe: Detect Network / VPN Connection Part 2 Pin
Richard MacCutchan15-Nov-18 10:54
mveRichard MacCutchan15-Nov-18 10:54 
GeneralRe: Detect Network / VPN Connection Part 2 Pin
Kevin Marois15-Nov-18 11:07
professionalKevin Marois15-Nov-18 11:07 
AnswerRe: Detect Network / VPN Connection Part 2 Pin
Nitin S28-Dec-18 1:34
professionalNitin S28-Dec-18 1:34 
QuestionHow to copy also subfolders and their files from an certain folder? Pin
Member 1405587915-Nov-18 4:24
Member 1405587915-Nov-18 4:24 
QuestionRe: How to copy also subfolders and their files from an certain folder? Pin
Richard MacCutchan15-Nov-18 6:04
mveRichard MacCutchan15-Nov-18 6:04 
AnswerRe: How to copy also subfolders and their files from an certain folder? Pin
Luc Pattyn15-Nov-18 8:01
sitebuilderLuc Pattyn15-Nov-18 8:01 
QuestionParsing JSon Pin
pkfox15-Nov-18 3:57
professionalpkfox15-Nov-18 3:57 
Hi all, first of all I'm a novice when it comes to parsing Json Big Grin | :-D , I'm attempting ( with some success ) to get information from the OED API, this is my first attempt
C#
using System;
using System.IO;
using System.Net;
using System.Text;
using Newtonsoft.Json.Linq;

namespace OxfordDictionary
{
    class Program
        {

        static HttpWebRequest req = null;
        static string PrimeUrl = "https://od-api.oxforddictionaries.com:443/api/v1/entries/en/";
        static string uri = PrimeUrl + "crossword";
        static string theJson = "";
        static HttpWebResponse HWR_Response = null;
        static Stream respStream = null;
        static StreamReader sr = null;

        static void Main(string[] args)
        {
            req = (HttpWebRequest)HttpWebRequest.Create(uri);
            req.Headers.Add("app_id", "my id");
            req.Headers.Add("app_key", "app key");
            req.Method = WebRequestMethods.Http.Get;
            req.Accept = "application/json";

            HWR_Response = (HttpWebResponse)req.GetResponse();
            respStream = HWR_Response.GetResponseStream();
            sr = new StreamReader(respStream, Encoding.UTF8);
            theJson = @sr.ReadToEnd();
            sr.Close();

            var results = JObject.Parse(theJson)["results"]; 

            string value = "";
            string name = "";
            string output = "";
            foreach (JObject o in results.Children<JObject>())
            {
                foreach (JProperty p in o.Properties())
                {
                    name = p.Name;
                    foreach (var v in p.Values())
                    {
                        value = v.ToString();
                        output += value;
                    }
                }
            }
            Console.WriteLine(output);
            Console.ReadKey();
        }
    }
}

which returns
crossword{
  "entries": [
    {
      "etymologies": [
        "said to have been invented by the journalist Arthur Wynne, whose puzzle (called a ‘word-cross’) appeared in a Sunday newspaper, the New York World, on 21 December 1913"
      ],
      "grammaticalFeatures": [
        {
          "text": "Singular",
          "type": "Number"
        }
      ],
      "homographNumber": "000",
      "senses": [
        {
          "definitions": [
            "a puzzle consisting of a grid of squares and blanks into which words crossing vertically and horizontally are written according to clues"
          ],
          "domains": [
            "Games"
          ],
          "examples": [
            {
              "text": "she settled down to do the crossword"
            }
          ],
          "id": "m_en_gbus0236440.007",
          "short_definitions": [
            "puzzle consisting of grid of squares and blanks into which words crossing vertically and horizontally are written according to clues"
          ]
        }
      ],
      "variantForms": [
        {
          "text": "crossword puzzle"
        }
      ]
    }
  ],
  "language": "en",
  "lexicalCategory": "Noun",
  "pronunciations": [
    {
      "audioFile": "<a href="http://audio.oxforddictionaries.com/en/mp3/crossword_gb_1_8.mp3">http://audio.oxforddictionaries.com/en/mp3/crossword_gb_1_8.mp3</a>",
      "dialects": [
        "British English"
      ],
      "phoneticNotation": "IPA",
      "phoneticSpelling": "ˈkrɒswəːd"
    }
  ],
  "text": "crossword"
}headwordcrossword

the bit I'm interested in is
"definitions": [
            "a puzzle consisting of a grid of squares and blanks into which words crossing vertically and horizontally are written according to clues"

I've tried googling but can't find anything to help me, so my question is ? how can I parse definitions[0] ?
We can’t stop here, this is bat country - Hunter S Thompson RIP


modified 15-Nov-18 10:03am.

AnswerRe: Parsing JSon Pin
OriginalGriff15-Nov-18 4:13
mveOriginalGriff15-Nov-18 4:13 
GeneralRe: Parsing JSon Pin
pkfox15-Nov-18 4:22
professionalpkfox15-Nov-18 4:22 
GeneralRe: Parsing JSon Pin
pkfox15-Nov-18 5:10
professionalpkfox15-Nov-18 5:10 
GeneralRe: Parsing JSon Pin
OriginalGriff15-Nov-18 5:27
mveOriginalGriff15-Nov-18 5:27 
GeneralRe: Parsing JSon Pin
OriginalGriff15-Nov-18 5:42
mveOriginalGriff15-Nov-18 5:42 
GeneralRe: Parsing JSon Pin
pkfox15-Nov-18 22:23
professionalpkfox15-Nov-18 22:23 
GeneralRe: Parsing JSon Pin
OriginalGriff15-Nov-18 22:31
mveOriginalGriff15-Nov-18 22:31 
GeneralRe: Parsing JSon Pin
pkfox15-Nov-18 22:38
professionalpkfox15-Nov-18 22:38 
GeneralRe: Parsing JSon Pin
OriginalGriff15-Nov-18 23:03
mveOriginalGriff15-Nov-18 23:03 
GeneralRe: Parsing JSon Success Pin
pkfox15-Nov-18 23:19
professionalpkfox15-Nov-18 23:19 
GeneralRe: Parsing JSon Success Pin
OriginalGriff15-Nov-18 23:37
mveOriginalGriff15-Nov-18 23:37 
GeneralRe: Parsing JSon Success Pin
pkfox15-Nov-18 23:39
professionalpkfox15-Nov-18 23:39 
GeneralRe: Parsing JSon Success Pin
pkfox16-Nov-18 2:57
professionalpkfox16-Nov-18 2:57 
QuestionGuys need your help am trying to insert data in MS Access database but its giving me a "Syntax Error" and i cnt find the problem....please analyse it and help Pin
Member 1405572615-Nov-18 2:09
Member 1405572615-Nov-18 2:09 
AnswerRe: Guys need your help am trying to insert data in MS Access database but its giving me a "Syntax Error" and i cnt find the problem....please analyse it and help Pin
OriginalGriff15-Nov-18 2:17
mveOriginalGriff15-Nov-18 2:17 
AnswerRe: Guys need your help am trying to insert data in MS Access database but its giving me a "Syntax Error" and i cnt find the problem....please analyse it and help Pin
Member 1332584615-Nov-18 21:00
Member 1332584615-Nov-18 21:00 
QuestionTo MD5 or not? (or SHA256 instead, I guess...) Pin
Super Lloyd14-Nov-18 15:34
Super Lloyd14-Nov-18 15:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.