Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Object Type and HTTP JSON Gets

Object Type and HTTP JSON Gets

Scheduled Pinned Locked Moved Web Development
javascriptregexjsonhelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cjb110
    wrote on last edited by
    #1

    I've been struggling with getting an Angular 6 app to sort the results of an WebAPI call, and it turns out that the root cause is case sensitivity on the object properties. And I can see 'where' the differing cases come from, but I can't see the where/why. I have a class for my object:

    export class App
    {
    id: number;
    name: string;
    description: string;
    isEnabled: boolean;
    shortName: string;
    displayOrder: number;
    }

    And my web service returns JSON like:

    {"ID":1
    ,"Name":"Matterhorn User Management"
    ,"Description":"User and Role management for Matterhorn applications."
    ,"IsEnabled":true
    ,"ShortName":"MUM"
    ,"DisplayOrder":10}

    To retrieve the data I've got the following function in my service:

    getApplications(): Observable
    {
    let apiURL: string = this.baseUrl + 'usermanagement/applications/read';

    return this.http.get(apiURL);
    

    }

    And finally my component calls that service function:

    getApps(): void
    {
    this.appsService.getApplications()
    .subscribe(data =>
    {
    this.apps = data.sort((a, b) => a.DisplayOrder - b.DisplayOrder);
    });

    }

    So the problem was that data structure matches the JSON capitalization and not my local TS object one, and I had to use DisplayOrder not displayOrder (and TS now whinges at me). But isn't Angular now supposed to map and convert JSON automatically (I know this was a specific step in the past)? And surely your local objects don't have to match the case sensitivity of the JSON provided by others.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups