I'm trying to implement the in App purchase mechanism in my iPhone app. To do so I need to make a json object out of the receipt string on my rails server, and send it to a iTunes server.
我正在尝试在我的iPhone应用程序中实现应用内购买机制。为此,我需要在我的rails服务器上的收据字符串中创建一个json对象,并将其发送到iTunes服务器。
- How can I create a json object out of a string? to_json didn't work for me...
- How can I send that json object to the specified Server and wait for the request...
如何从字符串中创建json对象? to_json对我不起作用......
如何将该json对象发送到指定的服务器并等待请求...
Thanks Maechi
2 个解决方案
#1
1
You asked: How can I create a json object out of a string?
你问:我怎样才能从字符串中创建一个json对象?
Is your string already in json format? If so, just send it along.
你的字符串是否已经是json格式?如果是这样,请发送它。
You'd use to_json when you have an object that you want to auto-turn into json. Example:
当你有一个想要自动变成json的对象时,你会使用to_json。例:
class InAppPurchase
attr_accessor :whatever, :whatever_x_two
end
purchase = InAppPurchase.new
purchase.whatever = "oh hai"
purchase.whatever_x_two = "good day"
purchase.to_json
Will output: {"whatever":"oh hai","whatever_x_two":"good day"}
将输出:{“whatever”:“oh hai”,“whatever_x_two”:“美好的一天”}
#2
0
You have to generate the "purchase request" from the iPhone and not the server. check out http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/StoreKitGuide/APIOverview/OverviewoftheStoreKitAPI.html#//apple_ref/doc/uid/TP40008267-CH100-SW1 for more details.
您必须从iPhone而不是服务器生成“购买请求”。有关详细信息,请查看http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/StoreKitGuide/APIOverview/OverviewoftheStoreKitAPI.html#//apple_ref/doc/uid/TP40008267-CH100-SW1。
#1
1
You asked: How can I create a json object out of a string?
你问:我怎样才能从字符串中创建一个json对象?
Is your string already in json format? If so, just send it along.
你的字符串是否已经是json格式?如果是这样,请发送它。
You'd use to_json when you have an object that you want to auto-turn into json. Example:
当你有一个想要自动变成json的对象时,你会使用to_json。例:
class InAppPurchase
attr_accessor :whatever, :whatever_x_two
end
purchase = InAppPurchase.new
purchase.whatever = "oh hai"
purchase.whatever_x_two = "good day"
purchase.to_json
Will output: {"whatever":"oh hai","whatever_x_two":"good day"}
将输出:{“whatever”:“oh hai”,“whatever_x_two”:“美好的一天”}
#2
0
You have to generate the "purchase request" from the iPhone and not the server. check out http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/StoreKitGuide/APIOverview/OverviewoftheStoreKitAPI.html#//apple_ref/doc/uid/TP40008267-CH100-SW1 for more details.
您必须从iPhone而不是服务器生成“购买请求”。有关详细信息,请查看http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/StoreKitGuide/APIOverview/OverviewoftheStoreKitAPI.html#//apple_ref/doc/uid/TP40008267-CH100-SW1。