1

我刚刚开始使用 Freebase API,我正在尝试使用 C# 将 JSON 结果解析为一个对象。我得到了一切都很好,但output领域。

例如,使用 Freebase 的output用法示例:

{
  "status": "200 OK",
  "result": [
    {
      "mid": "/m/017n9",
      "id": "/en/blade_runner",
      "name": "Blade Runner",
      "notable": {
        "name": "Future noir Film",
        "id": "/m/0279xh5"
      },
      "lang": "en",
      "score": 180.628250,
      "output": {
        "contributor": {
          "/film/film/cinematography": [
            {
              "mid": "/m/0fxgcv",
              "name": "Jordan Cronenweth"
            }
          ],
          "/film/film/costume_design_by": [
            {
              "mid": "/m/026ss4x",
              "name": "Michael Kaplan"
            },
            {
              "mid": "/m/04g09v4",
              "name": "Charles Knode"
            }
          ],
          "/film/film/directed_by": [
            {
              "mid": "/m/06chf",
              "name": "Ridley Scott"
            }
          ],
          "/film/film/edited_by": [
            {
              "mid": "/m/02x5kd2",
              "name": "Terry Rawlings"
            },
            {
              "mid": "/m/01xs0s0",
              "name": "Marsha Nakashima"
            }
          ],
          "/film/film/executive_produced_by": [
            {
              "mid": "/m/061fnq",
              "name": "Hampton Fancher"
            },
            {
              "mid": "/m/026_tq2",
              "name": "Brian Kelly"
            }
          ],
          "/film/film/film_art_direction_by": [
            {
              "mid": "/m/03qlfwr",
              "name": "David Snyder"
            }
          ],
          "/film/film/film_casting_director": [
            {
              "mid": "/m/0b3x558",
              "name": "Mike Fenton"
            },
            {
              "mid": "/m/07k6cmx",
              "name": "Marci Liroff"
            },
            {
              "mid": "/m/0b3x55h",
              "name": "Jane Feinberg"
            }
          ],
          "/film/film/film_production_design_by": [
            {
              "mid": "/m/05b5r87",
              "name": "Lawrence G. Paull"
            }
          ],
          "/film/film/film_set_decoration_by": [
            {
              "mid": "/m/05b2jc_",
              "name": "Linda DeScenna"
            },
            {
              "mid": "/m/0bvb08x",
              "name": "Leslie McCarthy-Frankenheimer"
            },
            {
              "mid": "/m/0b_3n1r",
              "name": "Peg Cummings"
            },
            {
              "mid": "/m/0c1m0xc",
              "name": "Thomas L. Roysden"
            }
          ],
          "/film/film/music": [
            {
              "mid": "/m/07zft",
              "name": "Vangelis"
            }
          ],
          "/film/film/produced_by": [
            {
              "mid": "/m/061fyk",
              "name": "Michael Deeley"
            },
            {
              "mid": "/m/026vbvh",
              "name": "Charles de Lauzirika"
            }
          ],
          "/film/film/production_companies": [
            {
              "mid": "/m/086k8",
              "name": "Warner Bros. Entertainment"
            },
            {
              "mid": "/m/0kqh5d",
              "name": "The Ladd Company"
            }
          ],
          "/film/film/story_by": [
            {
              "mid": "/m/05qzv",
              "name": "Philip K. Dick"
            }
          ],
          "/film/film/written_by": [
            {
              "mid": "/m/061fb6",
              "name": "David Peoples"
            },
            {
              "mid": "/m/061fnq",
              "name": "Hampton Fancher"
            }
          ],
          "/film/film_crew_gig/crewmember": [
            {
              "mid": "/m/044hvf",
              "name": "Douglas Trumbull"
            },
            {
              "mid": "/m/0bzjj60",
              "name": "Gerry Humphreys"
            },
            {
              "mid": "/m/0bbfh2m",
              "name": "Graham V. Hartstone"
            },
            {
              "mid": "/m/027prdy",
              "name": "Marvin Westmore"
            },
            {
              "mid": "/m/0h7ndj8",
              "name": "Bud Alper"
            },
            {
              "mid": "/m/0bnp6y1",
              "name": "Peter Pennell"
            }
          ],
          "/film/performance/actor": [
            {
              "mid": "/m/0c0k1",
              "name": "Harrison Ford"
            },
            {
              "mid": "/m/01xv77",
              "name": "Daryl Hannah"
            },
            {
              "mid": "/m/016yr0",
              "name": "Edward James Olmos"
            },
            {
              "mid": "/m/09byk",
              "name": "Rutger Hauer"
            },
            {
              "mid": "/m/0380zg",
              "name": "Sean Young"
            },
            {
              "mid": "/m/06lj1m",
              "name": "Joanna Cassidy"
            },
            {
              "mid": "/m/06qgjh",
              "name": "James Hong"
            },
            {
              "mid": "/m/05njj5",
              "name": "Brion James"
            },
            {
              "mid": "/m/045931",
              "name": "M. Emmet Walsh"
            },
            {
              "mid": "/m/05wqr1",
              "name": "William Sanderson"
            },
            {
              "mid": "/m/0czs9t",
              "name": "Joe Turkel"
            },
            {
              "mid": "/m/03d2k31",
              "name": "Morgan Paull"
            },
            {
              "mid": "/m/075jh5",
              "name": "Hy Pyke"
            },
            {
              "mid": "/m/0gccl1x",
              "name": "John Edward Allen"
            },
            {
              "mid": "/m/0gbzsdv",
              "name": "Kevin Thompson"
            }
          ]
        }
      }
    }
  ],
  "cursor": 1,
  "cost": 7,
  "hits": 530
}

我让这些对象使用 C# JavaScriptDeserllizer:

public class Notable
{
    public string name { get; set; }
    public string id { get; set; }
}

public class FilmFilmCinematography
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmFilmCostumeDesignBy
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmFilmDirectedBy
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmFilmEditedBy
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmFilmExecutiveProducedBy
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmFilmFilmArtDirectionBy
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmFilmFilmCastingDirector
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmFilmFilmProductionDesignBy
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmFilmFilmSetDecorationBy
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmFilmMusic
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmFilmProducedBy
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmFilmProductionCompany
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmFilmStoryBy
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmFilmWrittenBy
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmFilmCrewGigCrewmember
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class FilmPerformanceActor
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class MusicRecordingContributionContributor
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class MusicRecordingArtist
{
    public string mid { get; set; }
    public string name { get; set; }
}

public class Contributor
{
    public List<FilmFilmCinematography> filmfilmcinematography { get; set; }
    public List<FilmFilmCostumeDesignBy> filmfilmcostume_design_by { get; set; }
    public List<FilmFilmDirectedBy> filmfilmdirected_by { get; set; }
    public List<FilmFilmEditedBy> filmfilmedited_by { get; set; }
    public List<FilmFilmExecutiveProducedBy> filmfilmexecutive_produced_by { get; set; }
    public List<FilmFilmFilmArtDirectionBy> filmfilmfilm_art_direction_by { get; set; }
    public List<FilmFilmFilmCastingDirector> filmfilmfilm_casting_director { get; set; }
    public List<FilmFilmFilmProductionDesignBy> filmfilmfilm_production_design_by { get; set; }
    public List<FilmFilmFilmSetDecorationBy> filmfilmfilm_set_decoration_by { get; set; }
    public List<FilmFilmMusic> filmfilmmusic { get; set; }
    public List<FilmFilmProducedBy> filmfilmproduced_by { get; set; }
    public List<FilmFilmProductionCompany> filmfilmproduction_companies { get; set; }
    public List<FilmFilmStoryBy> filmfilmstory_by { get; set; }
    public List<FilmFilmWrittenBy> filmfilmwritten_by { get; set; }
    public List<FilmFilmCrewGigCrewmember> filmfilm_crew_gigcrewmember { get; set; }
    public List<FilmPerformanceActor> filmperformanceactor { get; set; }
    public List<MusicRecordingContributionContributor> musicrecording_contributioncontributor { get; set; }
    public List<MusicRecordingArtist> musicrecordingartist { get; set; }
}

public class Output
{
    public Contributor contributor { get; set; }
}

public class Result
{
    public string mid { get; set; }
    public string id { get; set; }
    public string name { get; set; }
    public Notable notable { get; set; }
    public string lang { get; set; }
    public double score { get; set; }
    public Output output { get; set; }
}

public class RootObject
{
    public string status { get; set; }
    public List<Result> result { get; set; }
    public int cursor { get; set; }
    public int cost { get; set; }
    public int hits { get; set; }
}

然而其中的所有字段output都是空的。我该如何解决这个问题?

4

1 回答 1

1

所以我已经能够使用JSONPropety解决它。我应该在字段上声明它以确保将正确的值转换为它们。

例如,这个:

public List<FilmFilmCinematography> filmfilmcinematography { get; set; }

...变成:

[JsonPropety("/film/film/cinematography")]    
public List<FilmFilmCinematography> filmfilmcinematography { get; set; }
于 2013-07-22T19:00:38.557 回答