1
I am creating an Asp.Net Web.API application and the return of service is in Json.
So far so good, it happens that the main object (Companies) is returning an internal object - citiesFiliais (Branches by City) with a Square Bracket that is not interpreted correctly by View.
In the View I already made a test including the object manually in the page without the inclusion of "[]" and this way when invoking {{city.city.}} the name of each City is displayed without any problem. But when invoking Json directly from the Backend the records for the object citiesFiliais are not displayed on the screen.
I already know that the only problem is the internal "[]" as mentioned above, the question is, how to make the return of the Backend equal to the 2nd example presented below?
1st Example - Current form of JSON:
{ "company": "Industria Reunidas", "fonePrincipal": "3030-9999", "citysFilials": [ { "city": "Belo Horizonte", "state": "MG", "ddd": 31 }, { "city": "Savior", "state": "BA", "area code": 71 }, { "city": "São Paulo", "state": "SP", "ddd": 11 } ] }
2nd Example - How JSON should be generated:
{ "company": "Industria Reunidas", "fonePrincipal": "3030-9999", "citysFilials": { "city": "Belo Horizonte", "state": "MG", "ddd": 31 }, { "city": "Savior", "state": "BA", "area code": 71 }, { "city": "São Paulo", "state": "SP", "ddd": 11 } }
Thank you for the force!!!
Ola Onosendai, I used the first example (with keys) on the link http://json.parser.online.fr/ and it was recognized without any problem! Is that my problem is not in Angularjs, ie when an internal Object comes with "[]" should use some specific property?
– urlflavio
@urlflavio Only the second example is invalid, the first one (generated by Webapi) is correct. Angular is also correctly evaluating the object. The JSON specification provides keys as collection delimiters (which is exactly what you want to express).
– OnoSendai
Okay Onosendai, if possible, see if I’m doing something wrong:
– urlflavio
Ok Onosendai, If possible, see if I am doing something wrong in the View: To present the phone company I am informing in the following way ==> <td>{{company.fonePrincipal}}</td> in this case the phone is presented correctly! but to present any record of "citiesFiliais" the record is not presented leaving the field blank ==> <td>{{company.citiesFiliais.city}}</td>. Am I missing something? I’m back to using the first example that’s returned from the API.
– urlflavio
@urlflavio Take a look at the example I included in the answer.
– OnoSendai
@urlflavio something else - being a collection,
empresa.cidadesFiliais.cidade
will fail becausecidadesFiliais
does not have a property calledcidade
. However you can use an index:empresa.cidadesFiliais[0].cidade
for the first member of the collection, for example.– OnoSendai
Onosendai, show dw ball the answer!!!! not wanting to abuse... :) if it were an object coming from a Onetoone relationship how would you do this assignment, ie as there would be no "ng-repeat" which angular property appropriate for this scenario? Muuuuito grateful for your help.
– urlflavio
@urlflavio No problem, it’s a pleasure to help. = ) In this case a 1x1 relationship can be expressed only as a property of the parent object.
– OnoSendai