2014-06-23 41 views
0

因此,這裏的陣列數組類型地圖

parts:[map[content:Phillip, 

This section pertains to terminated employees who are paid out in the year following the termination event. The way the tax law works, the tax basis for your share distribution will be based on the closing stock price the day preceding notification to the transfer agent. As such, we will distribute net shares calculating the proper withholding at fair market value the day prior to notifying the transfer agent. We will be distributing the shares reflected on your 9/30/01 statement (6,606 shares plus cash for fractional shares). If you would prefer to settle the taxes with a personal check, we can distribute gross shares. Please let me know you preference. 

As you know, we are in the process of transferring recordkeeping services from NTRC to Hewitt. As such, we have a CPA, Larry Lewis, working with us to audit and set up transition files. He has become our department expert on the PSA account (much more knowledgeable than myself) and the various plan provision amendments. If you would like, we can set up a conference call with you, myself, and Larry to go over the payment methodology. Please let me know a date and time that is convenient for you. 

Thanks, 

Renee 

-----Original Message----- 
From: Allen, Phillip K. 
Sent: Thursday, November 01, 2001 8:26 AM 
To: Ratcliff, Renee 
Subject: 

Renee, 

Thank you for digging in to the issue of Deferred Phantom Stock Units. It is clear that the payment will be made in shares. However, I still don't understand which date will be used to determine the value and calculate how many shares. The plan document under VII. Amount of Benefit Payments reads "The value of the shares, and resulting payment amount will be based on the closing price of Enron Corp. common stock on the January 1 before the date of payment, and such payment shall be made in shares of Enron Corp. common stock." Can you help me interpret this statement and work through the numbers on my account. 

Thank you, 

Phillip Allen 

contentType:text/plain]] 

我遇到試圖像

t := v["parts"][0].(map[string]interface{}) 

到「內容」我已經嘗試的事情,但這並沒有因爲工作的問題以及其他一些讓我進一步深入兔子洞的事情。

這些部分位於另一個映射字符串接口的內部。

這是我不斷收到

panic: interface conversion: interface is []interface {}, not map[string]interface {} 

這裏是JSON對象我解析錯誤。

{ 
    "X-cc": "", 
    "From": "[email protected]", 
    "X-Folder": "\\PALLEN (Non- Privileged)\\Allen, Phillip K.\\Inbox", 
    "Content-Transfer-Encoding": "7bit", 
    "X-bcc": "", "X-Origin": "Allen-P", 
    "To": ["[email protected]"], 
    "parts": [{ 
     "content": "Phillip,\r\n\r\nThis section pertains to terminated employees who are paid out in the year following the termination event. The way the tax law works, the tax basis for your share distribution will be based on the closing stock price the day preceding notification to the transfer agent. As such, we will distribute net shares calculating the proper withholding at fair market value the day prior to notifying the transfer agent. We will be distributing the shares reflected on your 9/30/01 statement (6,606 shares plus cash for fractional shares). If you would prefer to settle the taxes with a personal check, we can distribute gross shares. Please let me know you preference.\r\n\r\nAs you know, we are in the process of transferring recordkeeping services from NTRC to Hewitt. As such, we have a CPA, Larry Lewis, working with us to audit and set up transition files. He has become our department expert on the PSA account (much more knowledgeable than myself) and the various plan provision amendments. If you would like, we can set up a conference call with you, myself, and Larry to go over the payment methodology. Please let me know a date and time that is convenient for you.\r\n\r\nThanks,\r\n\r\nRenee\r\n\r\n -----Original Message-----\r\nFrom: \tAllen, Phillip K. \r\nSent:\tThursday, November 01, 2001 8:26 AM\r\nTo:\tRatcliff, Renee\r\nSubject:\t\r\n\r\nRenee,\r\n\r\nThank you for digging in to the issue of Deferred Phantom Stock Units. It is clear that the payment will be made in shares. However, I still don't understand which date will be used to determine the value and calculate how many shares. The plan document under VII. Amount of Benefit Payments reads \"The value of the shares, and resulting payment amount will be based on the closing price of Enron Corp. common stock on the January 1 before the date of payment, and such payment shall be made in shares of Enron Corp. common stock.\" Can you help me interpret this statement and work through the numbers on my account.\r\n\r\nThank you,\r\n\r\nPhillip Allen\r\n\r\n", 

    "contentType": "text/plain"}], 
    "X-FileName": "PALLEN (Non-Privileged).pst", 
    "Mime-Version": "1.0", 
    "X-From": "Ratcliff, Renee </O=ENRON/OU=NA/CN=RECIPIENTS/CN=RRATCLI>", 
    "Date": {"$date": 1004725111000}, 
    "X-To": "Allen, Phillip K. </O=ENRON/OU=NA/CN=RECIPIENTS/CN=Pallen>", 
    "Message-ID": "<[email protected]>", 
    "Content-Type": "text/plain; charset=us-ascii", "Subject": "RE:" 
} 

這是代碼。

http://play.golang.org/p/rJPTjvoM_t

+0

這是安然電子郵件從早在2011年或類似的東西時,整個醜聞是怎麼回事。 –

回答

0

請張貼的您已經嘗試什麼,你正在嘗試做一個實際的例子。

陣列的地圖和地圖陣列的行爲像任何其他類型。

在您的例子,它看起來像你想有一個map[string][]map[string]interface{}但你必須map[string][]interface{}與你的界面是一個[]interface{}

下面是使用地圖/接口/陣列/片+一個失敗的一些示例內容你顯示。 (​​)

package main 

import "fmt" 

type Content struct { 
     name string 
} 

func main() { 
     arrayOfMap := [2]map[string]Content{ 
       {"part1": {name: "Philip"}}, 
       {"part2": {name: "John"}}, 
     } 
     fmt.Printf("%s\n", arrayOfMap[0]["part1"].name) 

     mapOfArray := map[string][2]Content{ 
       "parts": { 
         {name: "Philip"}, 
         {name: "John"}, 
       }, 
     } 
     fmt.Printf("%s\n", mapOfArray["parts"][0].name) 

     mapOfArrayOfMap := map[string][2]map[string]Content{ 
       "parts": { 
         {"subpart": Content{name: "Philips"}}, 
       }, 
     } 
     fmt.Printf("%s\n", mapOfArrayOfMap["parts"][0]["subpart"].name) 

     mapOfArrayOfInterface := map[string][2]interface{}{ 
       "parts": { 
         map[string]interface{}{"content": Content{name: "Philips"}}, 
       }, 
     } 
     fmt.Printf("%s\n", mapOfArrayOfInterface["parts"][0].(map[string]interface{})["content"].(Content).name) 

     mapOfArrayOfSliceInterface := map[string][2][]interface{}{ 
       "parts": { 
         { 
           map[string]interface{}{ 
             "content": Content{name: "Philips"}, 
           }, 
         }, 
       }, 
     } 
     fmt.Printf("%s\n", mapOfArrayOfSliceInterface["parts"][0][0].(map[string]interface{})["content"].(Content).name) 

     v := map[string][]interface{}{ 
       "parts": []interface{}{ 
         0: []interface{}{nil}, 
       }, 
     } 
     // This will fail as shown in the given example. 
     fmt.Printf("%s\n", v["parts"][0].(map[string]interface{})) 
} 
+0

Hopeully這有助於我繼續,只是張貼在play.golang http://play.golang.org/p/rJPTjvoM_t 例如JSON是上述 –

+0

連接我重寫了一個位的自由而不改變邏輯。您試圖訪問map [string] interface {}作爲切片。您應該執行一個類型斷言來映射[string] [] interface {}來執行此操作。 http://play.golang.org/p/I2rJe22J_l – creack

+0

但通常情況下,您不想解組到接口。最好是知道你的數據並解開已知的類型。 http://play.golang.org/p/F3Y1TG5-XY。 – creack

0

好了,所以從上面的意見採取了許多事情之後......我想說的是什麼@creack曾是最接近能夠從多維獲得的「內容」的價值接口類型是以下鏈接。

http://play.golang.org/p/urBQ8NxSo8