jquery - JavaScript / JSON Recursive Logic Issue using hasOwnProperty -


Here is JSON, the typical problem is the comment // currently does not parse

  var oarsObject = [{ "coordinateReferenceSystem": "26782,15851 & lt; - not a price", "positionReferenceType": "geogWgs84", "geogWgs84": { "latitude": { "value ".50018514607964015}," longitude ": {" value ": -1.587237735514361}," height ": {" value ": 0.0}}}, {" coordinateReferenceSystem ": {" value ":" Do 26782,15851 & lt - had a value "}," PositionReferenceType ": {" value ":" GeogWgs84 "}," GeogWgs84 ": {" latitude ": {" value ": 0.5001841257180204}," longitude ": {" value ": - 1.5869069927615211}, "height": { "Price": 0.0}}}, { "coordinateReferenceSystem": "26782,15851", "positionReferenceType": "geogWgs84", "geogWgs84": { "latitude": { "value": .49997645018241949}, "longitude": { "value": -1.5869078356348387}, "height": { "value": 0.0}}}, { "coordinateReferenceSystem": "26782,15851", "positionReferenceType": "Geo GWgs84", "GeogWgs84": { "latitude "{" Value ": .4999774704207946}," longitude ": {" value ": {1.5872385394554729}," height ": {" value ": 0.0}}," nest ": {" level_1 ": {" child_1 " : {"Value": "child_1 & lt; - level 1 "," gchild_1 ": {" value ":" gchild_1 & lt; - level 2 "} // can not be found {{" gchild_1 ": {" gchild_1 ": {" gchild_1 ": {" value ":" gchild_1 "& lt; - level 2 "}}," child_3 ": {" gchild_2 ": {" ggchild_1 ": {" value ":" Ggchild_1 & lt; - Level 3 "}}}}}}}   

I thought the recursion was working very well, but then the case of the top edge came in where the extra property was given in the items Where a "value" property exists. I have a few options, I can get different JSON spit or I can try to account for these side cases, which seems to be more scalable for me here How am I going and now recursive -

  f Unction propertyTest {for (various assets in current object) {if (currentObject [property] .hasOwnProperty ('value')) / If "value" boots fits $ ('# method 1'). Property + ',' + current object [property] .value + '

(if the current object type [properties] === "object") {// recurring when necessary Properties (exits [property]);} and {// "zero" information exits $ ('# method 1') .Append (+ Property + "+ Current Current Crop [property] + '& lt; br / & gt;');}}}

Divel only one way to test to add feature. The code is probably not clear as it should be right now, but I will clear it later on.

Question - How do I properly recap / it so that I can recover the case values ​​of these sides? Any suggestions or help would be appreciated!

You can use something like this

  function propertyTest {for (var asset in present object) {if (currentObject [property] .hasOwnProperty ('value')) {$ ('# method1'). append (property + ',' + current object [property] .value + '
|); } If (type of current object [properties] === "object") {propertyTest (current object [property]); } And if (property! = 'Value') {$ ('# method 1'). Append (property + "+ current object [property] + '
); }}}

I simplify this:

  function propertyTest (current object, key) {for (different CurrentObject in property) {if (currentof typeobject [property] === "object") {propertyTest (current object [property], property); } And {$ ('# method1'). Append ((property == 'value' & key key + ',' property) + "+ current object [property] + '
;); }}}



Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -