2011-11-10 35 views
0

我申請了一份工作,並得到了一些測試。它非常簡單,但我必須處理他們提供的格式不正確的JSON對象。做的JSON對象需要格式正確嗎?

我不知道這是否正常(我對JSON很新穎)? (OK意味着我仍然可以將它用作標準的JSON對象)。

這裏是JSON字符串:

{"title": "Carbon Market Trader EU", 
    "link": "cmteu", 
    "children": [ 
     {"title": "Analysis", 
     "link": "analysis", 
     "children": [ 
      {"title": "Daily Reports", 
       "link": "daily", 
       "children": [ 
        {"title": "Forward", 
         "link": "fwd", 
          "children": [ 

          {"title": "Morning Report", "link": "morning"}, 
          {"title": "Benchmark", "link": "bench"} 
         ]} 
      ]}, 
      {"title": "Weekly Reports", 
       "link": "weekly", 
       "children": [ 
        {"title": "Forward", 
        "link": "fwd", 
        "children": [ 
         {"title": "Weekly Report","link": "weekly"} 
        ]} 
      ]}, 
      {"title": "Monthly Reports","link": "mth"}, 
      {"title": "Price Forecasts", 
       "link": "pfc", 
       "children": [ 
        {"title": "Price Forecasts","link": "pfc"}, 
        {"title": "Supply and Demand","link": "sad"} 
      ]}, 
      {"title": "Policy Updates","link": "pup"}, 
      {"title": "Analyst Updates","link": "aup"}, 
      {"title": "Carbon Market Brief","link": "cmb"}, 
      {"title": "Report Library","link": "ml"}, 
      {"title": "Reuters Insider","link": "ri"}, 
      {"title": "Market Indicators", 
       "link": "mi", 
       "children": [ 
        {"title": "Overview","link": "overview"}, 
        {"title": "Breakdown", 
         "link": "breakdown" 
         "children": [ 
          {"title": "Cross Commodity Indicators","link": "cci"}, 
          {"title": "Technical Indicators","link": "ti"}, 
          {"title": "Fundamental Indicators","link": "fi"}, 
          {"title": "Information Indicators","link": "ii"} 
        ]} 
      ]} 
    ]}, 
    {"title": "Supply", 
     "link": "supply", 
     "children": [ 
      {"title": "Cap","link": "cap"}, 
      {"title": "Overview","link": "overview"}, 
      {"title": "Reserves","link": "reserves"} 
    ]}, 
    {"title": "Demand", 
     "link": "demand", 
     "children": [ 
      {"title": "Emissions Forecast","link": "ef"}, 
      {"title": "Power and Heat Emissions","link": "phe"}, 
      {"title": "Industry Emissions","link": "ie"} 
    ]}, 
    {"title": "Market Data", 
    "link": "md", 
    "children": [ 
     {"title": "Carbon", 
     "link": "carbon", 
     "children": [ 
      {"title": "Forward", 
      "link": "fwd", 
       "children": [ 
        {"title": "EUA","link": "eua"}, 
        {"title": "sCER","link": "cer"}, 
        {"title": "RGA","link": "rga"} 
      ]} 
     ]}, 
     {"title": "Coal", 
     "link": "coal", 
     "children": [ 
      {"title": "Forward", 
      "link": "fwd", 
      "children": [ 
       {"title": "API-2","link": "api"} 
      ]} 
     ]}, 
     {"title": "Crude oil", 
     "link": "crude", 
     "children": [ 
      {"title": "Forward", 
      "link": "fwd", 
      "children": [ 
       {"title": "Brent","link": "brent"} 
      ]} 
     ]} 
    ]} 
]} 
+0

http://jsonlint.com – BalusC

回答

1

嘗試將該對象傳遞給「eval()」 - 失敗。無效的JSON。 (我不得不承認,很難看清楚爲什麼,雖然)

+0

我使用了許多在線解析,並且它們都失敗了。想知道這是否是一個問題。由於它不符合eval方法,我想它確實很重要,所以我會發送一封郵件給僱主,告訴他們JSON不會工作。 –

+0

是的,如果它失敗了「eval()」,那麼它不是消費品......可以想象,一些json解析器將能夠處理它,但它會是非常糟糕的設計指望,即使你找到一個沒有。 – Aerik

+0

謝謝。我現在已經發送了一封郵件給發送給我的人,並要求她重新發送,或者我應該修復它。 –

1

請使用http://jsonlint.com/

這並不好。

+0

是的,我知道它沒有正確格式化,因此問題。我想知道這是否重要。我想你的答案是這樣的。 –

+0

@PJK:它可能是有用的解釋確切_why_它不好。 – Kyle