2013-06-24 2 views
7

Yesod의 처리기에서 가장 간단한 JSON 응답을 작성하려고하지만 정말로 어리석은 오류가 발생합니다.yesod 처리기에서 JSON을 반환하십시오.

Handler/Echo.hs:12:10: 
    Couldn't match expected type `RepJson' with actual type `Value' 
    In the first argument of `return', namely `json' 
    In a stmt of a 'do' block: return json 
    In the expression: 
     do { let json = object $ ...; 
      return json } 
Build failure, pausing... 

답변

6

나도 이것에 의해 잡힌 : 당신이 당신 타입의 서명을 변경해야하고 작동합니다

getEchoR :: String -> Handler Value 

-- HelloYesod/Handler/Echo.hs 
module Handler.Echo where 

import   Data.Aeson  (object, (.=)) 
import qualified Data.Aeson  as J 
import   Data.Text  (pack) 
import   Import 
import   Yesod.Core.Json (returnJson) 

getEchoR :: String -> Handler RepJson 
getEchoR theText = do 
    let json = object $ ["data" .= "val"] 
    return json 

오류는 이것이다 : 내 처리기 코드는 이것이다

제 생각에는 Rep 시스템 전체가 Yesod 1.2에서 사용되지 않으므로 Handler는 RepHtml 및 RepJson 대신 Html 및 Value를 반환합니다.

희망이 도움이됩니다.

+0

Yesod 1.2의 변경 사항은이 문서 (https://github.com/yesodweb/yesod/wiki/Detailed-change-list)를 확인하는 것이 좋습니다. – thoferon