2014-11-01 56 views
0

我有以下JSON文件json file从哪里我需要读取内容(客户端请求是与jQuery) - 我的问题:文件中有多个数组 - 是任何选项只能读取特定数组?具有多个阵列内容的JSON文件读取

或需要阅读所有,然后我可以逐一处理? (这也可以) - 直到现在我只用一个“简单”数组来处理文件,但是这个有多个数组的我没有经验。

请让我知道什么是解析此文件内容的最佳模式/方法。 或 其他方法可以工作。

可能只从文件读取一个数组? -

谢谢!

+0

你想从Ajax响应?并想获得特别的回应说“Base.pricing.packages”列表? – Asik 2014-11-01 15:40:09

+0

我需要用ajax读取文件,是的,我需要文件的所有内容,通过访问参数数组 - 通过做不同的事情 – 2014-11-01 21:20:35

回答

0

您的JSON文件不包含真正的JSON字符串...您需要更改文件如下

检查demo

JSON文件(temp.json)

{ 

    "packages": [ 
     "Core", 
     "Comms", 
     "Standards", 
     "Content", 
     "Events", 
     "Advertising", 
     "Training", 
     "Personal development", 
     "Opportunity matching", 
     "Deployment", 
     "Affiliates", 
     "Verification" 
    ], 
    "bundles": { 
     "Just Checks": [ ], 
     "Compliance": [ 
      "Core", 
      "Standards" 
     ], 
     "Comply & Engage": [ 
      "Core", 
      "Comms", 
      "Standards", 
      "Events" 
     ], 
     "Full Staff Bank": [ 
      "Core", 
      "Comms", 
      "Standards", 
      "Events", 
      "Opportunity matching", 
      "Deployment" 
     ] 
    }, 
    "pricing": { 
     "packages": { 
      "Core": { 
       "25": "25.00", 
       "100": "38.58", 
       "300": "69.44", 
       "1,000": "125.00", 
       "2,000": "200.00", 
       "5,000": "320.00", 
       "10,000": "416.00", 
       "50,000": "540.80", 
       "50000+": "703.04" 
      }, 
      "Comms": { 
       "25": "13.33", 
       "100": "20.58", 
       "300": "37.04", 
       "1,000": "66.67", 
       "2,000": "106.67", 
       "5,000": "170.67", 
       "10,000": "221.87", 
       "50,000": "288.43", 
       "50000+": "374.95" 
      }, 
      "Standards": { 
       "25": "10.00", 
       "100": "15.43", 
       "300": "27.78", 
       "1,000": "50.00", 
       "2,000": "80.00", 
       "5,000": "128.00", 
       "10,000": "166.40", 
       "50,000": "216.32", 
       "50000+": "281.22" 
      }, 
      "Content": { 
       "25": "6.67", 
       "100": "10.29", 
       "300": "18.52", 
       "1,000": "33.33", 
       "2,000": "53.33", 
       "5,000": "85.33", 
       "10,000": "110.93", 
       "50,000": "144.21", 
       "50000+": "187.48" 
      }, 
      "Events": { 
       "25": "6.67", 
       "100": "10.29", 
       "300": "18.52", 
       "1,000": "33.33", 
       "2,000": "53.33", 
       "5,000": "85.33", 
       "10,000": "110.93", 
       "50,000": "144.21", 
       "50000+": "187.48" 
      }, 
      "Advertising": { 
       "25": "13.33", 
       "100": "20.58", 
       "300": "37.04", 
       "1,000": "66.67", 
       "2,000": "106.67", 
       "5,000": "170.67", 
       "10,000": "221.87", 
       "50,000": "288.43", 
       "50000+": "374.95" 
      }, 
      "Training": { 
       "25": "2.50", 
       "100": "3.86", 
       "300": "6.94", 
       "1,000": "12.50", 
       "2,000": "20.00", 
       "5,000": "32.00", 
       "10,000": "41.60", 
       "50,000": "54.08", 
       "50000+": "70.30" 
      }, 
      "Personal development": { 
       "25": "13.33", 
       "100": "20.58", 
       "300": "37.04", 
       "1,000": "66.67", 
       "2,000": "106.67", 
       "5,000": "170.67", 
       "10,000": "221.87", 
       "50,000": "288.43", 
       "50000+": "374.95" 
      }, 
      "Opportunity matching": { 
       "25": "13.33", 
       "100": "20.58", 
       "300": "37.04", 
       "1,000": "66.67", 
       "2,000": "106.67", 
       "5,000": "170.67", 
       "10,000": "221.87", 
       "50,000": "288.43", 
       "50000+": "374.95" 
      }, 
      "Deployment": { 
       "25": "13.33", 
       "100": "20.58", 
       "300": "37.04", 
       "1,000": "66.67", 
       "2,000": "106.67", 
       "5,000": "170.67", 
       "10,000": "221.87", 
       "50,000": "288.43", 
       "50000+": "374.95" 
      }, 
      "Affiliates": { 
       "25": "30.00", 
       "100": "46.30", 
       "300": "83.33", 
       "1,000": "150.00", 
       "2,000": "240.00", 
       "5,000": "384.00", 
       "10,000": "499.20", 
       "50,000": "648.96", 
       "50000+": "843.65" 
      }, 
      "Verification": { 
       "25": "25.00", 
       "100": "38.58", 
       "300": "69.44", 
       "1,000": "125.00", 
       "2,000": "200.00", 
       "5,000": "320.00", 
       "10,000": "416.00", 
       "50,000": "540.80", 
       "50000+": "703.04" 
      } 
     }, 
     "checks": { 
      "DBS Standard Disclosure": { 
       "Just Checks": { 
        "25": "10", 
        "100": "10", 
        "300": "9", 
        "1,000": "8", 
        "2,000": "7.50", 
        "5,000": "6.50", 
        "10,000": "6", 
        "50,000": "6", 
        "50000+": "6" 
       }, 
       "Compliance": { 
        "25": "10", 
        "100": "10", 
        "300": "9", 
        "1,000": "8", 
        "2,000": "7.50", 
        "5,000": "6.50", 
        "10,000": "6", 
        "50,000": "6", 
        "50000+": "6" 
       }, 
       "Comply & Engage": { 
        "25": "10", 
        "100": "10", 
        "300": "9", 
        "1,000": "8", 
        "2,000": "7.50", 
        "5,000": "6.50", 
        "10,000": "6", 
        "50,000": "6", 
        "50000+": "6" 
       }, 
       "Full Staff Bank": { 
        "25": "10", 
        "100": "10", 
        "300": "9", 
        "1,000": "8", 
        "2,000": "7.50", 
        "5,000": "6.50", 
        "10,000": "6", 
        "50,000": "6", 
        "50000+": "6" 
       } 
      }, 
      "DBS Enhanced Disclosure": { 
       "Just Checks": { 
        "25": "10", 
        "100": "10", 
        "300": "9", 
        "1,000": "8", 
        "2,000": "7.50", 
        "5,000": "6.50", 
        "10,000": "6", 
        "50,000": "6", 
        "50000+": "6" 
       }, 
       "Compliance": { 
        "25": "10", 
        "100": "10", 
        "300": "9", 
        "1,000": "8", 
        "2,000": "7.50", 
        "5,000": "6.50", 
        "10,000": "6", 
        "50,000": "6", 
        "50000+": "6" 
       }, 
       "Comply & Engage": { 
        "25": "10", 
        "100": "10", 
        "300": "9", 
        "1,000": "8", 
        "2,000": "7.50", 
        "5,000": "6.50", 
        "10,000": "6", 
        "50,000": "6", 
        "50000+": "6" 
       }, 
       "Full Staff Bank": { 
        "25": "10", 
        "100": "10", 
        "300": "9", 
        "1,000": "8", 
        "2,000": "7.50", 
        "5,000": "6.50", 
        "10,000": "6", 
        "50,000": "6", 
        "50000+": "6" 
       } 
      }, 
      "Address & ID Check": { 
       "Just Checks": { 
        "25": "6", 
        "100": "6", 
        "300": "6", 
        "1,000": "5", 
        "2,000": "5", 
        "5,000": "5", 
        "10,000": "3", 
        "50,000": "3", 
        "50000+": "3" 
       }, 
       "Compliance": { 
        "25": "6", 
        "100": "6", 
        "300": "6", 
        "1,000": "5", 
        "2,000": "5", 
        "5,000": "5", 
        "10,000": "3", 
        "50,000": "3", 
        "50000+": "3" 
       }, 
       "Comply & Engage": { 
        "25": "6", 
        "100": "6", 
        "300": "6", 
        "1,000": "5", 
        "2,000": "5", 
        "5,000": "5", 
        "10,000": "3", 
        "50,000": "3", 
        "50000+": "3" 
       }, 
       "Full Staff Bank": { 
        "25": "6", 
        "100": "6", 
        "300": "6", 
        "1,000": "5", 
        "2,000": "5", 
        "5,000": "5", 
        "10,000": "3", 
        "50,000": "3", 
        "50000+": "3" 
       } 
      }, 
      "Right to Work": { 
       "Just Checks": { 
        "25": "9", 
        "100": "9", 
        "300": "9", 
        "1,000": "8", 
        "2,000": "8", 
        "5,000": "7", 
        "10,000": "6", 
        "50,000": "6", 
        "50000+": "6" 
       }, 
       "Compliance": { 
        "25": "9", 
        "100": "9", 
        "300": "9", 
        "1,000": "8", 
        "2,000": "8", 
        "5,000": "7", 
        "10,000": "6", 
        "50,000": "6", 
        "50000+": "6" 
       }, 
       "Comply & Engage": { 
        "25": "9", 
        "100": "9", 
        "300": "9", 
        "1,000": "8", 
        "2,000": "8", 
        "5,000": "7", 
        "10,000": "6", 
        "50,000": "6", 
        "50000+": "6" 
       }, 
       "Full Staff Bank": { 
        "25": "9", 
        "100": "9", 
        "300": "9", 
        "1,000": "8", 
        "2,000": "8", 
        "5,000": "7", 
        "10,000": "6", 
        "50,000": "6", 
        "50000+": "6" 
       } 
      } 
     } 
    } 

} 

Jquery Ajax

$("button").click(function(){ 
    $.ajax({url:"temp.json",success:function(result){ 
     console.log(result.pricing.packages); 
    }}); 
}); 

HTML

<button>Get Price Packages</button> 
+0

谢谢,这是我需要的 – 2014-11-03 09:01:33