Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8790487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:40:10+00:00 2026-06-13T22:40:10+00:00

I’m working on a custom add in for excel, I want it to get

  • 0

I’m working on a custom add in for excel, I want it to get a list of projects from a remote web service. The JSON is coming back from the web servive to excel, but I’m having trouble turning the JSON into objects in C#.

Here is the AddIn code:

using Microsoft.Office.Tools.Ribbon;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Web;

namespace TestAddIn
{
    class Project
    {
        static string currentProject;
        static List<Project> validProjects;

        public int id { get; set; }
        public string name { get; set; }
        public int svar_reserved_space { get; set; }

        // Set the current project we're working on
        internal static void setCurrentProject(string path)
        {
            Match match = Regex.Match(path, @"^[A-Za-z]:\\(\w+)");

            Project.currentProject = match.Groups[1].Value;

            foreach (Project validProject in validProjects)
            {
                RibbonDropDownItem dropDown = Globals.Ribbons.Ribbon1.Factory.CreateRibbonDropDownItem();

                dropDown.Label = validProject.name;

                if (validProject.name.Equals(Project.currentProject))
                {
                    Globals.Ribbons.Ribbon1.projectComboBox.Items.Add(dropDown);
                }
            }
        }

        // Connect to a web service and get a list of valid projects
        internal static void getValidProjects()
        {
            string url = "http://192.168.118.128/projects/json";

            WebRequest webRequest;
            webRequest = WebRequest.Create(url);

            Stream objStream;
            objStream = webRequest.GetResponse().GetResponseStream();

            StreamReader objReader = new StreamReader(objStream);

            string sLine = objReader.ReadLine();

            Debug.WriteLine("begin: " + sLine);

            validProjects = JsonConvert.DeserializeObject<List<Project>>(sLine);

            Debug.WriteLine("end");
        }
    }
}

When using this json:

[{"Project":{"id":1,"name":"test1","svar_reserved_space":2}},{"Project":{"id":2,"name":"test2","svar_reserved_space":0}}]

I get two Project objects in validProjects but the id and svar_reserver_space are 0, and the name is null. Thoguhts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:40:11+00:00Added an answer on June 13, 2026 at 10:40 pm

    This is the easiest with some addins/nuget magic:

    • Install web essentials in Visual studio
    • Add the nuget package newtonsoft.json
    • Copy the JSON output string
    • Paste JSON as class

    And use this code:

    WebClient wc = new WebClient();
    string json = wc.DownloadString("http://192.168.118.128/projects/json");
    var a = JsonConvert.DeserializeObject<YourGeneratedMainClass>(json);
    

    Where YourGeneratedMainClass is a class generated by pasting the json as classes.

    If you use the method above, you will probably see that it has a parent object

    public class Project
    {
        public int id { get; set; }
        public string name { get; set; }
        public int svar_reserved_space { get; set; }
    }
    
    public class Parent
    {
        public Project Project { get; set; }
    }
    

    More about it in these two S.O. questions:

    Json.net deseralize to a list of objects in c# .net 2.0

    Deserialized Object Has All Values Set to Null

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.